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) ⇒ ValkyrieUpload
constructor
A new instance of ValkyrieUpload.
- #upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil) ⇒ Object
Constructor Details
#initialize(storage_adapter: Hyrax.storage_adapter) ⇒ ValkyrieUpload
Returns a new instance of ValkyrieUpload.
33 34 35 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 33 def initialize(storage_adapter: Hyrax.storage_adapter) @storage_adapter = storage_adapter 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.
70 71 72 73 74 75 76 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 70 def add_file_to_file_set(file_set:, file_metadata:, user:) file_set.file_ids << .id set_file_use_ids(file_set, ) 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) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/services/hyrax/valkyrie_upload.rb', line 37 def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil) streamfile = storage_adapter.upload(file: io, original_filename: filename, resource: file_set) = Hyrax::FileMetadata(streamfile) .file_set_id = file_set.id .type += [use] 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: ) Hyrax.publisher.publish("object.file.uploaded", metadata: ) add_file_to_file_set(file_set: file_set, file_metadata: , user: user) Hyrax.publisher.publish('file.metadata.updated', metadata: , user: user) end |