Class: SdrClient::RedesignedClient::UploadFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/redesigned_client/upload_files.rb

Overview

The file uploading part of a deposit

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_metadata:, filepath_map:) ⇒ UploadFiles

Returns a new instance of UploadFiles.

Parameters:

  • file_metadata (Hash<String,DirectUploadRequest>)

    map of relative filepaths to file metadata

  • filepath_map (Hash<String,String>)

    map of relative filepaths to absolute filepaths



15
16
17
18
# File 'lib/sdr_client/redesigned_client/upload_files.rb', line 15

def initialize(file_metadata:, filepath_map:)
  @file_metadata = 
  @filepath_map = filepath_map
end

Class Method Details

.upload(file_metadata:, filepath_map:) ⇒ Object

Parameters:

  • file_metadata (Hash<String,DirectUploadRequest>)

    map of relative filepaths to file metadata

  • filepath_map (Hash<String,String>)

    map of relative filepaths to absolute filepaths



9
10
11
# File 'lib/sdr_client/redesigned_client/upload_files.rb', line 9

def self.upload(file_metadata:, filepath_map:)
  new(file_metadata: , filepath_map: filepath_map).upload
end

Instance Method Details

#uploadArray<DirectUploadResponse>

Returns the responses from the server for the uploads.

Returns:



21
22
23
24
25
26
27
28
29
30
# File 'lib/sdr_client/redesigned_client/upload_files.rb', line 21

def upload
  .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(response)
      logger.info("Upload of #{filepath} complete")
    end
  end
end