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

[31205] Fix attachment disposition for local files

Oliver Günther50828e930a26
diff --git a/lib/api/helpers/attachment_renderer.rb b/lib/api/helpers/attachment_renderer.rb
index 5ae693317f0..49fbe4d4ff6 100644
--- a/lib/api/helpers/attachment_renderer.rb
+++ b/lib/api/helpers/attachment_renderer.rb
@@ -43,7 +43,7 @@ module API
redirect attachment.external_url.to_s
else
content_type attachment.content_type
- header['Content-Disposition'] = attachment.content_disposition
+ header['Content-Disposition'] = "#{attachment.content_disposition}; filename=#{attachment.filename}"
env['api.format'] = :binary
attachment.diskfile.read
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 ccace9fe912..a67429ddf8a 100644
--- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
+++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
@@ -287,14 +287,14 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
context 'for a local text file' do
it_behaves_like 'for a local file' do
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.txt' }
- let(:content_disposition) { "inline" }
+ let(:content_disposition) { "inline; filename=foobar.txt" }
end
end
context 'for a local binary file' do
it_behaves_like 'for a local file' do
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.dat', content_type: "application/octet-stream" }
- let(:content_disposition) { "attachment" }
+ let(:content_disposition) { "attachment; filename=foobar.dat" }
end
end