uploads: allow uploading multiple files from your computer at once.

Allow uploading multiple files from your computer at once.

The maximum limit is 100 files at once. There is still a 50MB size limit
that applies to the whole upload. This limit is at the Nginx level.

The upload widget no longer shows a thumbnail preview of the uploaded
file. This is because there isn't room for it in a multi-file upload,
and because the next page will show a preview anyway after the files are
uploaded.

Direct file uploads are processed synchronously, so they may be slow.

API change: the `POST /uploads` endpoint now expects the param to be
`upload[files][]`, not `upload[file]`.
This commit is contained in:
evazion
2022-02-18 23:08:17 -06:00
parent e37dd3a6d0
commit 202dfe5d87
10 changed files with 79 additions and 51 deletions

View File

@@ -162,7 +162,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
assert_no_difference("Upload.count") do
file = File.open("test/files/test.jpg")
source = "https://files.catbox.moe/om3tcw.webm"
post_auth uploads_path(format: :json), @user, params: { upload: { file: file, source: source }}
post_auth uploads_path(format: :json), @user, params: { upload: { files: { "0" => file }, source: source }}
end
assert_response 422
@@ -171,7 +171,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
should "fail if given an unsupported filetype" do
file = Rack::Test::UploadedFile.new("test/files/ugoira.json")
post_auth uploads_path(format: :json), @user, params: { upload: { file: file }}
post_auth uploads_path(format: :json), @user, params: { upload: { files: { "0" => file } }}
assert_response 201
assert_match("File is not an image or video", Upload.last.error)
@@ -247,12 +247,9 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
context "when re-uploading a media asset stuck in the 'processing' state" do
should "mark the asset as failed" do
asset = create(:media_asset, file: File.open("test/files/test.jpg"), status: "processing")
file = Rack::Test::UploadedFile.new("test/files/test.jpg")
create_upload!("test/files/test.jpg", user: @user)
post_auth uploads_path, @user, params: { upload: { file: file }}
upload = Upload.last
assert_redirected_to upload
assert_match("Upload failed, try again", upload.reload.error)
assert_equal("failed", asset.reload.status)
end
@@ -287,6 +284,24 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
# should_upload_successfully("test/files/compressed.swf")
end
context "uploading multiple files from your computer" do
should "work" do
files = {
"0" => Rack::Test::UploadedFile.new("test/files/test.jpg"),
"1" => Rack::Test::UploadedFile.new("test/files/test.png"),
"2" => Rack::Test::UploadedFile.new("test/files/test.gif"),
}
post_auth uploads_path(format: :json), @user, params: { upload: { files: files }}
upload = Upload.last
assert_response 201
assert_equal("", upload.error.to_s)
assert_equal("completed", upload.status)
assert_equal(3, upload.media_asset_count)
end
end
context "uploading a file from a source" do
should_upload_successfully("https://www.artstation.com/artwork/04XA4")
should_upload_successfully("https://dantewontdie.artstation.com/projects/YZK5q")