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

Correctly pass the filename to the UploadedFile

Oliver Günther0e8f96bb1851
diff --git a/lib/api/v3/attachments/attachment_parsing_representer.rb b/lib/api/v3/attachments/attachment_parsing_representer.rb
index 34c37354896..563d496ce0d 100644
--- a/lib/api/v3/attachments/attachment_parsing_representer.rb
+++ b/lib/api/v3/attachments/attachment_parsing_representer.rb
@@ -35,12 +35,6 @@ module API
module V3
module Attachments
class AttachmentParsingRepresenter < ::API::Decorators::Single
- property :file,
- setter: ->(fragment:, **) {
- self.file = OpenProject::Files.build_uploaded_file fragment[:tempfile],
- fragment[:type]
- }
-
nested :metadata do
property :filename,
as: :fileName
@@ -63,6 +57,14 @@ module API
property :digest,
render_nil: false
end
+
+ property :file,
+ setter: ->(fragment:, represented:, doc:, **) {
+ filename = represented.filename || doc.dig('metadata', 'fileName')
+ self.file = OpenProject::Files.build_uploaded_file fragment[:tempfile],
+ fragment[:type],
+ file_name: filename
+ }
end
end
end