Patch #25115

Support upload of empty files and fix invalid API response

Added by Jens Krämer 8 months ago. Updated 8 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Attachments
Target version:3.3.3

Description

When Uploading an empty file through the REST API (POST to /uploads.json), the response is 201 Created, and an invalid token (which that does not resolve to an attachment through Attachment.find_by_token because it lacks the digest component) is returned. However an attachment record is still saved, but without a corresponding file in the file system.

When looking into this I found that the easiest fix for this would be to change the two conditionals in attachment.rb that prevent an empty file from being treated like any non-empty file. I don't see any technical reason to not allow the uploading of empty files, and my change doesn't seem to cause any of the existing tests to fail.

Attached is a patch which does that, including a test case illustrating the inconsistent API behavior I described above.

0001-fixes-uploading-of-empty-files.patch Magnifier (2.65 KB) Jens Krämer, 2017-02-17 15:23

0001-fixes-uploading-of-empty-files-v2.patch Magnifier - extended patch with acts_as_attachable fix (3.61 KB) Jens Krämer, 2017-02-19 08:02


Related issues

Related to Redmine - Defect #5969: Attachments with size zero are ignored Closed 2010-07-27

Associated revisions

Revision 16341
Added by Jean-Philippe Lang 8 months ago

Fixes uploading of empty files (#25115).

- prevents creation of attachment records without existing diskfile and empty
digest
- adds test case to check file upload API response
- also removes the file size check in ActsAsAttachable which still prevented
attachment of zero size attachments to containers but only for clients
without Javascript (where save_attachments is called with the actual file
upload).

Patch by Jens Kraemer.

History

#1 Updated by Go MAEDA 8 months ago

  • Related to Defect #5969: Attachments with size zero are ignored added

#2 Updated by Go MAEDA 8 months ago

  • Target version set to 3.3.3

This patch also fixes the issue reported as #5969.

#3 Updated by Jens Krämer 8 months ago

Here's an extended version of the patch. This one also removes the file size check in acts_as_attachable which prevented empty attachment creation for http uploads without javascript (in all other cases this part of the code isn't relevant since save_attachments is called with just the tokens of already saved attachments).

This patch replaces the original one.

#4 Updated by Jean-Philippe Lang 8 months ago

  • Subject changed from support upload of empty files and fix invalid API response to Support upload of empty files and fix invalid API response
  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang

Patch committed, thanks.

#5 Updated by Jean-Philippe Lang 8 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF