Fix-up variants controller

上级 1c85eece
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
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册