Support upload of empty files and fix invalid API response
|Assignee:||Jean-Philippe Lang||% Done:|
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.
Fixes uploading of empty files (#25115).
- prevents creation of attachment records without existing diskfile and empty
- 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
Patch by Jens Kraemer.
#3 Updated by Jens Krämer almost 2 years ago
- File 0001-fixes-uploading-of-empty-files-v2.patch added
save_attachments is called with just the tokens of already saved attachments).
This patch replaces the original one.