Class: Factorix::Transfer::Uploader
- Inherits:
-
Object
- Object
- Factorix::Transfer::Uploader
- Defined in:
- lib/factorix/transfer/uploader.rb,
sig/factorix/transfer/uploader.rbs
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
Constant Summary collapse
- URI =
Instance Attribute Summary collapse
-
#client ⇒ HTTP::Client
readonly
Returns the value of attribute client.
-
#logger ⇒ Dry::Logger::Dispatcher
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize ⇒ Uploader
constructor
A new instance of Uploader.
-
#upload(url, file_path, field_name: "file", fields: {}, content_type: :auto) ⇒ void
Upload a file to the given URL with optional form fields.
Constructor Details
#initialize ⇒ Uploader
Returns a new instance of Uploader.
11 |
# File 'sig/factorix/transfer/uploader.rbs', line 11
def initialize: (**untyped deps) -> void
|
Instance Attribute Details
#client ⇒ HTTP::Client (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'sig/factorix/transfer/uploader.rbs', line 9 def client @client end |
#logger ⇒ Dry::Logger::Dispatcher (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'sig/factorix/transfer/uploader.rbs', line 8 def logger @logger end |
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 |