diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 17:34:32 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 17:34:32 -0500 |
commit | 6c2cef21ce67f83bff45ce76c0370b03be11451f (patch) | |
tree | 7337844165e56c2d2c44e13751ff6d4554be86c7 | |
parent | 1c85eecee02ebf0c0148de807fbb1a9e9573af8a (diff) | |
download | rails-6c2cef21ce67f83bff45ce76c0370b03be11451f.tar.gz rails-6c2cef21ce67f83bff45ce76c0370b03be11451f.tar.bz2 rails-6c2cef21ce67f83bff45ce76c0370b03be11451f.zip |
Fix-up variants controller
-rw-r--r-- | app/controllers/active_storage/direct_uploads_controller.rb | 11 | ||||
-rw-r--r-- | lib/active_storage/controllers/variants_controller.rb | 22 |
2 files changed, 11 insertions, 22 deletions
diff --git a/app/controllers/active_storage/direct_uploads_controller.rb b/app/controllers/active_storage/direct_uploads_controller.rb new file mode 100644 index 0000000000..dccd864e8d --- /dev/null +++ b/app/controllers/active_storage/direct_uploads_controller.rb @@ -0,0 +1,11 @@ +class ActiveStorage::DirectUploadsController < ActionController::Base + def create + blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args) + render json: { url: blob.url_for_direct_upload, sgid: blob.to_sgid.to_param } + end + + private + def blob_args + params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :metadata).to_h.symbolize_keys + end +end diff --git a/lib/active_storage/controllers/variants_controller.rb b/lib/active_storage/controllers/variants_controller.rb deleted file mode 100644 index 094f94e706..0000000000 --- a/lib/active_storage/controllers/variants_controller.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "action_controller" -require "active_storage/blob" - -class ActiveStorage::Controllers::VariantsController < ActionController::Base - def show - if blob_key = decode_verified_key - variant = ActiveStorage::Variant.find_or_create_by(blob_key: blob_key, variation_key: params[:variation_key]) - redirect_to variant.url - else - head :not_found - end - end - - private - def decode_verified_key - ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_key]) - end - - def disposition_param - params[:disposition].presence_in(%w( inline attachment )) || 'inline' - end -end |