Class: SdrClient::Deposit::UploadFiles
- Inherits:
-
Object
- Object
- SdrClient::Deposit::UploadFiles
- Defined in:
- lib/sdr_client/deposit/upload_files.rb
Overview
The file uploading part of a deposit
Constant Summary collapse
- BLOB_PATH =
'/v1/direct_uploads'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file_metadata:, filepath_map:, logger:, connection:) ⇒ UploadFiles
constructor
A new instance of UploadFiles.
-
#run ⇒ Array<Files::DirectUploadResponse>
The responses from the server for the uploads.
Constructor Details
#initialize(file_metadata:, filepath_map:, logger:, connection:) ⇒ UploadFiles
Returns a new instance of UploadFiles.
21 22 23 24 25 26 |
# File 'lib/sdr_client/deposit/upload_files.rb', line 21 def initialize(file_metadata:, filepath_map:, logger:, connection:) @file_metadata = @filepath_map = filepath_map @logger = logger @connection = connection end |
Class Method Details
.upload(file_metadata:, filepath_map:, logger:, connection:) ⇒ Object
13 14 15 |
# File 'lib/sdr_client/deposit/upload_files.rb', line 13 def self.upload(file_metadata:, filepath_map:, logger:, connection:) new(file_metadata: , filepath_map: filepath_map, logger: logger, connection: connection).run end |
Instance Method Details
#run ⇒ Array<Files::DirectUploadResponse>
Returns the responses from the server for the uploads.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sdr_client/deposit/upload_files.rb', line 29 def run .map do |filepath, | direct_upload(.to_json).tap do |response| # ActiveStorage modifies the filename provided in response, so setting here with the relative filename response.filename = filepath upload_file(filename: filepath, url: response.direct_upload.fetch('url'), content_type: response.content_type, content_length: response.byte_size) logger.info("Upload of #{filepath} complete") end end end |