Class: SdrClient::RedesignedClient::DirectUploadRequest
- Inherits:
-
Struct
- Object
- Struct
- SdrClient::RedesignedClient::DirectUploadRequest
- Defined in:
- lib/sdr_client/redesigned_client/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
7 8 9 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 7 def byte_size @byte_size end |
#checksum ⇒ Object
Returns the value of attribute checksum
7 8 9 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 7 def checksum @checksum end |
#content_type ⇒ Object
Returns the value of attribute content_type
7 8 9 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 7 def content_type @content_type end |
#filename ⇒ Object
Returns the value of attribute filename
7 8 9 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 7 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
35 36 37 38 39 40 41 42 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 35 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
8 9 10 11 12 13 14 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 8 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
#to_h ⇒ Object
16 17 18 19 20 21 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 16 def to_h { 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
23 24 25 |
# File 'lib/sdr_client/redesigned_client/direct_upload_request.rb', line 23 def to_json(*_args) JSON.generate(to_h) end |