diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 0bd1b736..16eb5f35 100755 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -33,6 +33,8 @@ def self.attachable_to 'image/bmp', 'image/jpeg', 'image/jpg', + 'image/heic', + 'image/heif', 'image/gif', 'image/png', 'application/pdf', @@ -45,13 +47,14 @@ def self.attachable_to /png|PNG\z/, /jpg|JPG\z/, /jpeg|JPEG\z/, + /heif|HEIF\z/, + /heic|HEIC\z/, /pdf|PDF\z/, /gif|GIF\z/, /zip|ZIP\z/, /rar|RAR\z/, ] - def attached_to_something return unless attached_to.nil? errors.add(:base, 'must_be_attached_to_something') diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 5ae01f9d..5382322a 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1 +1,2 @@ -Paperclip::DataUriAdapter.register \ No newline at end of file +Paperclip::DataUriAdapter.register +Paperclip.options[:content_type_mappings] = { heic: 'image/heic', heif: 'image/heif' } \ No newline at end of file diff --git a/spec/fixtures/files/simple.heic b/spec/fixtures/files/simple.heic new file mode 100644 index 00000000..1e61cb3d Binary files /dev/null and b/spec/fixtures/files/simple.heic differ diff --git a/spec/helpers/request_helpers.rb b/spec/helpers/request_helpers.rb index dc250d84..ab591e1c 100644 --- a/spec/helpers/request_helpers.rb +++ b/spec/helpers/request_helpers.rb @@ -38,7 +38,7 @@ def api_response def mime_for(ext) case ext - when :bmp, :png, :jpg, :jpeg, :JPEG, :gif, :BMP, :JPG, :PNG, :GIF then "image/#{ext.downcase}" + when :bmp, :png, :jpg, :jpeg, :JPEG, :gif, :BMP, :JPG, :PNG, :GIF, :heic, :heif, :HEIC, :HEIF then "image/#{ext.downcase}" when :pdf, :zip, :PDF, :ZIP then "application/#{ext.downcase}" when :rar, :RAR then "application/x-rar-compressed" else raise "No fixture for #{ext.downcase} files" diff --git a/spec/requests/api/attachments_spec.rb b/spec/requests/api/attachments_spec.rb index 56ba0be1..510b95d3 100644 --- a/spec/requests/api/attachments_spec.rb +++ b/spec/requests/api/attachments_spec.rb @@ -47,6 +47,32 @@ end end + it 'handles heic images' do + allow_any_instance_of(Paperclip::MediaTypeSpoofDetector).to( + receive(:type_from_file_command).and_return('image/heic') + ) + issue = create(:basic_issue) + seed = create(:full_natural_docket_seed, + issue: issue, add_all_attachments: false) + + api_create "/attachments", + { + type: "attachments", + relationships: {attached_to_seed: {data: {id: seed.id, type: 'natural_docket_seeds'}}}, + attributes: { + document: "data:#{mime_for(:heic)};base64,#{bytes_for(:heic)}", + document_file_name: 'simple.heic', + document_content_type: mime_for(:heic) + } + } + file_attachment = api_response.data + + api_get "/attachments/#{file_attachment.id}" + expect(api_response.data.relationships.attached_to_seed.data.to_h).to( + eq(type: 'natural_docket_seeds', id: seed.id.to_s) + ) + end + it "Can validate max people request limit on show" do Redis.new.flushall