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:
@@ -3,6 +3,8 @@
|
||||
class UploadMediaAsset < ApplicationRecord
|
||||
extend Memoist
|
||||
|
||||
attr_accessor :file
|
||||
|
||||
belongs_to :upload
|
||||
belongs_to :media_asset, optional: true
|
||||
has_one :post, through: :media_asset
|
||||
@@ -62,16 +64,22 @@ class UploadMediaAsset < ApplicationRecord
|
||||
end
|
||||
|
||||
def async_process_upload!
|
||||
return if file_upload?
|
||||
ProcessUploadMediaAssetJob.perform_later(self)
|
||||
if file.present?
|
||||
process_upload!
|
||||
else
|
||||
ProcessUploadMediaAssetJob.perform_later(self)
|
||||
end
|
||||
end
|
||||
|
||||
def process_upload!
|
||||
return if file_upload?
|
||||
update!(status: :processing)
|
||||
|
||||
strategy = Sources::Strategies.find(source_url)
|
||||
media_file = strategy.download_file!(source_url)
|
||||
if file.present?
|
||||
media_file = MediaFile.open(file)
|
||||
else
|
||||
media_file = source_strategy.download_file!(source_url)
|
||||
end
|
||||
|
||||
MediaAsset.upload!(media_file) do |media_asset|
|
||||
update!(media_asset: media_asset)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user