Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix for downloading attachments that are JSON files.

Wieland Lindenthal61c6bf5ec214
diff --git a/lib/api/helpers/attachment_renderer.rb b/lib/api/helpers/attachment_renderer.rb
index 6b9b1d81517..e866147692a 100644
--- a/lib/api/helpers/attachment_renderer.rb
+++ b/lib/api/helpers/attachment_renderer.rb
@@ -49,7 +49,7 @@ module API
content_type attachment.content_type
header['Content-Disposition'] = "#{attachment.content_disposition}; filename=#{attachment.filename}"
env['api.format'] = :binary
- attachment.diskfile.read
+ file attachment.diskfile
end
end
diff --git a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
index 33829dd9eb7..043c857323f 100644
--- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
+++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
@@ -298,6 +298,15 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
end
end
+ context 'for a local json file' do
+ it_behaves_like 'for a local file' do
+ let(:mock_file) { FileHelpers.mock_uploaded_file ({ name: 'foobar.json',
+ content_type: "application/json",
+ content: '{"id": "12342"}' }) }
+ let(:content_disposition) { "attachment; filename=foobar.json" }
+ end
+ end
+
context 'for a remote file' do
let(:external_url) { 'http://some_service.org/blubs.gif' }
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.txt' }