Class: Factorix::Transfer::Uploader
- Inherits:
-
Object
- Object
- Factorix::Transfer::Uploader
- Defined in:
- lib/factorix/transfer/uploader.rb
Overview
File uploader with automatic retry
Uploads files to given URLs using HTTP multipart/form-data. Uses Transfer::HTTP for the actual upload with event-driven progress notification.
Defined Under Namespace
Classes: CombinedIO, ProgressIO
Instance Method Summary collapse
-
#upload(url, file_path, field_name: "file", fields: {}, content_type: :auto) ⇒ void
Upload a file to the given URL with optional form fields.
Instance Method Details
#upload(url, file_path, field_name: "file", fields: {}, content_type: :auto) ⇒ void
This method returns an undefined value.
Upload a file to the given URL with optional form fields
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/factorix/transfer/uploader.rb', line 49 def upload(url, file_path, field_name: "file", fields: {}, content_type: :auto) url = URI(url) if url.is_a?(String) unless url.is_a?(URI::HTTPS) logger.error("Invalid URL: must be HTTPS", url: url.to_s) raise URLError, "URL must be HTTPS" end unless file_path.exist? logger.error("File does not exist", path: file_path.to_s) raise ConfigurationError, "File does not exist: #{file_path}" end resolved_content_type = content_type == :auto ? detect_content_type(file_path) : content_type upload_file_with_progress(url, file_path, field_name, fields, resolved_content_type) end |