app/services/hyrax/valkyrie_persist_derivatives.rb in hyrax-4.0.0 vs app/services/hyrax/valkyrie_persist_derivatives.rb in hyrax-5.0.0.rc1

- old
+ new

@@ -20,24 +20,21 @@ directives, uploader: Hyrax::ValkyrieUpload.new(storage_adapter: Hyrax.config.derivatives_storage_adapter)) file_set = fileset_for_directives(directives) # Valkyrie storage adapters will typically expect an IO-like object that - # responds to #path -- here we only have a StringIO, so some - # transformation is in order + # responds to #rewind and #read so we have created a StringIO tmpfile = Tempfile.new(file_set.id, encoding: 'ascii-8bit') - tmpfile.write stream.read + stream = StringIO.new(stream) if stream.is_a?(String) + stream.rewind + output = tmpfile.write(stream.read) + tmpfile.flush + raise 'blank file detected' if output.zero? filename = filename(directives) - Hyrax.logger.debug "Uploading thumbnail for FileSet #{file_set.id} as #{filename}" - - uploader.upload( - io: tmpfile, - filename: filename, - file_set: file_set, - use: Hyrax::FileMetadata::Use::THUMBNAIL - ) + Hyrax.logger.debug "Uploading derivative for FileSet #{file_set.id} as #{filename}" + uploader.upload(io: tmpfile, filename: filename, file_set: file_set, use: file_metadata(directives)) end # The filepath will look something like # /app/samvera/hyrax-webapp/derivatives/95/93/tv/12/3-thumbnail.jpeg and # we want to extract the FileSet id, which in this case would be 9593tv123 @@ -54,8 +51,16 @@ Hyrax.metadata_adapter.query_service.find_by(id: id) end def self.filename(directives) URI(directives.fetch(:url)).path.split('/').last + end + + def self.file_metadata(directives) + if directives.key?(:container) + "Hyrax::FileMetadata::Use::#{directives[:container].upcase}".constantize + else + Hyrax::FileMetadata::Use::THUMBNAIL + end end end end