Class: Hyrax::ValkyrieUpload
- Inherits:
-
Object
- Object
- Hyrax::ValkyrieUpload
- Defined in:
- app/services/hyrax/valkyrie_upload.rb
Instance Attribute Summary collapse
-
#storage_adapter ⇒ Object
readonly
Returns the value of attribute storage_adapter.
Class Method Summary collapse
-
.file(filename:, file_set:, io:, storage_adapter: Hyrax.storage_adapter, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil) ⇒ Hyrax::FileMetadata
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/ParameterLists.
Instance Method Summary collapse
-
#add_file_to_file_set(file_set:, file_metadata:, user:) ⇒ Hyrax::FileSet
Updated file set.
-
#initialize(storage_adapter: Hyrax.storage_adapter, file_set_file_service: Hyrax.config.file_set_file_service) ⇒ ValkyrieUpload
constructor
A new instance of ValkyrieUpload.
-
#upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil, mime_type: nil) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #version_upload(file_set:, io:, user:) ⇒ Object
Constructor Details
#initialize(storage_adapter: Hyrax.storage_adapter, file_set_file_service: Hyrax.config.file_set_file_service) ⇒ ValkyrieUpload
Returns a new instance of ValkyrieUpload.
34 35 36 37 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 34 def initialize(storage_adapter: Hyrax.storage_adapter, file_set_file_service: Hyrax.config.file_set_file_service) @storage_adapter = storage_adapter @file_set_file_service = file_set_file_service end |
Instance Attribute Details
#storage_adapter ⇒ Object (readonly)
Returns the value of attribute storage_adapter.
30 31 32 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 30 def storage_adapter @storage_adapter end |
Class Method Details
.file(filename:, file_set:, io:, storage_adapter: Hyrax.storage_adapter, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil) ⇒ Hyrax::FileMetadata
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/ParameterLists
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 15 def self.file( filename:, file_set:, io:, storage_adapter: Hyrax.storage_adapter, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil ) new(storage_adapter: storage_adapter) .upload(filename: filename, file_set: file_set, io: io, use: use, user: user) end |
Instance Method Details
#add_file_to_file_set(file_set:, file_metadata:, user:) ⇒ Hyrax::FileSet
Returns updated file set.
85 86 87 88 89 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 85 def add_file_to_file_set(file_set:, file_metadata:, user:) file_set.file_ids += [.id] Hyrax.persister.save(resource: file_set) Hyrax.publisher.publish('object.membership.updated', object: file_set, user: user) end |
#upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil, mime_type: nil) ⇒ Object
rubocop:disable Metrics/AbcSize
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 39 def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil, mime_type: nil) # rubocop:disable Metrics/AbcSize return version_upload(file_set: file_set, io: io, user: user) if use == Hyrax::FileMetadata::Use::ORIGINAL_FILE && file_set.original_file_id && storage_adapter.supports?(:versions) streamfile = storage_adapter.upload(file: io, original_filename: filename, resource: file_set) = Hyrax::FileMetadata(streamfile) .file_set_id = file_set.id .pcdm_use = [use] .recorded_size = [io.size] .mime_type = mime_type if mime_type .original_filename = File.basename(filename).to_s || File.basename(io) if use == Hyrax::FileMetadata::Use::ORIGINAL_FILE # Set file set label. reset_title = file_set.title.first == file_set.label # set title to label if that's how it was before this characterization file_set.title = .original_filename if reset_title # always set the label to the original_name file_set.label = .original_filename end = Hyrax.persister.save(resource: ) .original_filename = filename if .original_filename.blank? add_file_to_file_set(file_set: file_set, file_metadata: , user: user) Hyrax.publisher.publish("file.uploaded", metadata: ) Hyrax.publisher.publish('file.metadata.updated', metadata: , user: user) end |
#version_upload(file_set:, io:, user:) ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 71 def version_upload(file_set:, io:, user:) = @file_set_file_service.primary_file_for(file_set: file_set) Hyrax::VersioningService.create(, user, io) Hyrax.publisher.publish("file.uploaded", metadata: ) ContentNewVersionEventJob.perform_later(file_set, user) end |