FIX: Better 0 file size detection and logging (#16116)

When creating files with create-multipart, if the file
size was somehow zero we were showing a very unhelpful
error message to the user. Now we show a nicer message,
and proactively don't call the API if we know the file
size is 0 bytes in JS, along with extra console logging
to help with debugging.
This commit is contained in:
Martin Brennan
2022-03-07 12:39:33 +10:00
committed by GitHub
parent 5f5acfa064
commit 7af01d88d2
7 changed files with 37 additions and 4 deletions

View File

@ -825,6 +825,22 @@ describe UploadsController do
expect(response.body).to include(I18n.t("upload.attachments.too_large_humanized", max_size: "1 MB"))
end
it 'returns a sensible error if the file size is 0 bytes' do
SiteSetting.authorized_extensions = "*"
stub_create_multipart_request
post "/uploads/create-multipart.json", **{
params: {
file_name: "test.zip",
file_size: 0,
upload_type: "composer",
}
}
expect(response.status).to eq(422)
expect(response.body).to include(I18n.t("upload.size_zero_failure"))
end
def stub_create_multipart_request
FileStore::S3Store.any_instance.stubs(:temporary_upload_path).returns(
"uploads/default/#{test_bucket_prefix}/temp/28fccf8259bbe75b873a2bd2564b778c/test.png"