Class: SdrClient::Deposit::Files::DirectUploadRequest
- Inherits:
-
Struct
- Object
- Struct
- SdrClient::Deposit::Files::DirectUploadRequest
- Defined in:
- lib/sdr_client/deposit/files/direct_upload_request.rb
Instance Attribute Summary collapse
-
#byte_size ⇒ Object
Returns the value of attribute byte_size.
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
-
.clean_and_translate_content_type(content_type) ⇒ Object
Invalid JSON files with a content type of application/json will trigger 400 errors in sdr-api since they are parsed and rejected (not clear why and what part of the stack is doing this).
- .from_file(path, file_name:, content_type:) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#byte_size ⇒ Object
Returns the value of attribute byte_size
6 7 8 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 6 def byte_size @byte_size end |
#checksum ⇒ Object
Returns the value of attribute checksum
6 7 8 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 6 def checksum @checksum end |
#content_type ⇒ Object
Returns the value of attribute content_type
6 7 8 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 6 def content_type @content_type end |
#filename ⇒ Object
Returns the value of attribute filename
6 7 8 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 6 def filename @filename end |
Class Method Details
.clean_and_translate_content_type(content_type) ⇒ Object
Invalid JSON files with a content type of application/json will trigger 400 errors in sdr-api since they are parsed and rejected (not clear why and what part of the stack is doing this). The work around is to change the content_type for any JSON files to a custom stand-in and specific to avoid the parsing, and then have this translated back to application/json after . upload is complete. There is a corresponding change in sdr-api to translate the content_type back before the Cocina is saved. See github.com/sul-dlss/happy-heron/issues/3075 for the original bug report See github.com/sul-dlss/sdr-api/pull/585 for the change in sdr-api
34 35 36 37 38 39 40 41 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 34 def self.clean_and_translate_content_type(content_type) return 'application/octet-stream' if content_type.blank? # ActiveStorage is expecting "application/x-stata-dta" not "application/x-stata-dta;version=14" content_type = content_type.split(';').first content_type == 'application/json' ? 'application/x-stanford-json' : content_type end |
.from_file(path, file_name:, content_type:) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 7 def self.from_file(path, file_name:, content_type:) checksum = Digest::MD5.file(path).base64digest new(checksum: checksum, byte_size: ::File.size(path), content_type: clean_and_translate_content_type(content_type), filename: file_name) end |
Instance Method Details
#as_json ⇒ Object
15 16 17 18 19 20 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 15 def as_json { blob: { filename: filename, byte_size: byte_size, checksum: checksum, content_type: self.class.clean_and_translate_content_type(content_type) } } end |
#to_json(*_args) ⇒ Object
22 23 24 |
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 22 def to_json(*_args) JSON.generate(as_json) end |