Patch #25115 » 0001-fixes-uploading-of-empty-files.patch
app/models/attachment.rb | ||
---|---|---|
85 | 85 |
def file=(incoming_file) |
86 | 86 |
unless incoming_file.nil? |
87 | 87 |
@temp_file = incoming_file |
88 |
if @temp_file.size > 0 |
|
89 | 88 |
if @temp_file.respond_to?(:original_filename) |
90 | 89 |
self.filename = @temp_file.original_filename |
91 | 90 |
self.filename.force_encoding("UTF-8") |
... | ... | |
94 | 93 |
self.content_type = @temp_file.content_type.to_s.chomp |
95 | 94 |
end |
96 | 95 |
self.filesize = @temp_file.size |
97 |
end |
|
98 | 96 |
end |
99 | 97 |
end |
100 | 98 | |
... | ... | |
110 | 108 |
# Copies the temporary file to its final location |
111 | 109 |
# and computes its MD5 hash |
112 | 110 |
def files_to_final_location |
113 |
if @temp_file && (@temp_file.size > 0)
|
|
111 |
if @temp_file |
|
114 | 112 |
self.disk_directory = target_directory |
115 | 113 |
self.disk_filename = Attachment.disk_filename(filename, disk_directory) |
116 | 114 |
logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)") if logger |
test/integration/api_test/attachments_test.rb | ||
---|---|---|
197 | 197 |
end |
198 | 198 |
end |
199 | 199 |
end |
200 | ||
201 |
test "POST /uploads.json should create an empty file and return a valid token" do |
|
202 |
set_tmp_attachments_directory |
|
203 |
assert_difference 'Attachment.count' do |
|
204 |
post '/uploads.json', '', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) |
|
205 |
assert_response :created |
|
206 | ||
207 |
end |
|
208 | ||
209 |
json = ActiveSupport::JSON.decode(response.body) |
|
210 |
assert_kind_of Hash, json['upload'] |
|
211 |
token = json['upload']['token'] |
|
212 |
assert token.present? |
|
213 | ||
214 |
assert attachment = Attachment.find_by_token(token) |
|
215 |
assert_equal 0, attachment.filesize |
|
216 |
assert attachment.digest.present? |
|
217 |
assert File.exist? attachment.diskfile |
|
218 |
end |
|
200 | 219 |
end |