Class: Hydra::Works::UploadFileToFileSet

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/works/services/upload_file_to_file_set.rb

Class Method Summary collapse

Class Method Details

.call(file_set, file, additional_services: [], update_existing: true, versioning: true) ⇒ Object

Sets a file as the primary file (original_file) of the file_set

Parameters:

  • file_set (Hydra::PCDM::FileSet)

    the file will be added to

  • object (IO, File, Rack::Multipart::UploadedFile, #read)

    that will be the contents. If file responds to :mime_type or :original_name, those will be called to provide technical metadata.

  • additional_services (Array) (defaults to: [])

    (ie Generating Thumbnails) to call with file_set after adding the file as its original_file

  • update_existing (Boolean) (defaults to: true)

    whether to update an existing file if there is one. When set to true, performs a create_or_update. When set to false, always creates a new file within file_set.files.

  • versioning (Boolean) (defaults to: true)

    whether to create new version entries (only applicable if type corresponds to a versionable file)



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hydra/works/services/upload_file_to_file_set.rb', line 10

def self.call(file_set, file, additional_services: [], update_existing: true, versioning: true)
  Hydra::Works::AddFileToFileSet.call(file_set, file, :original_file, update_existing: update_existing, versioning: versioning)

  # Call any additional services
  additional_services.each do |service|
    service.call(file_set)
  end

  file_set.save
  file_set
end