mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
Merge branch 'hotfix/1.17.11' into develop
This commit is contained in:
commit
a819e1b8f4
1 changed files with 27 additions and 0 deletions
27
app/controllers/active_storage/direct_uploads_controller.rb
Normal file
27
app/controllers/active_storage/direct_uploads_controller.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActiveStorage
|
||||
class DirectUploadsController < CustomBaseController
|
||||
def create
|
||||
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args)
|
||||
render json: direct_upload_json(blob)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def blob_args
|
||||
args = params.require(:blob)
|
||||
.permit(:filename, :byte_size, :checksum, :content_type, :metadata)
|
||||
.to_h
|
||||
.symbolize_keys
|
||||
args[:content_type] = 'application/octet-stream' if args[:content_type].blank?
|
||||
args
|
||||
end
|
||||
|
||||
def direct_upload_json(blob)
|
||||
blob.as_json(root: false, methods: :signed_id)
|
||||
.merge(direct_upload: { url: blob.service_url_for_direct_upload,
|
||||
headers: blob.service_headers_for_direct_upload })
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue