mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of github.com:rails/activestorage
This commit is contained in:
commit
6de1c0b7b5
6 changed files with 18 additions and 16 deletions
|
@ -115,7 +115,7 @@ class ActiveStorage::Blob < ActiveRecord::Base
|
|||
# Returns a URL that can be used to directly upload a file for this blob on the service. This URL is intended to be
|
||||
# short-lived for security and only generated on-demand by the client-side JavaScript responsible for doing the uploading.
|
||||
def service_url_for_direct_upload(expires_in: 5.minutes)
|
||||
service.url_for_direct_upload key, expires_in: expires_in, content_type: content_type, content_length: byte_size
|
||||
service.url_for_direct_upload key, expires_in: expires_in, content_type: content_type, content_length: byte_size, checksum: checksum
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class ActiveStorage::Service
|
|||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def url_for_direct_upload(key, expires_in:, content_type:, content_length:)
|
||||
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
|
|
|
@ -55,10 +55,10 @@ class ActiveStorage::Service::GCSService < ActiveStorage::Service
|
|||
end
|
||||
end
|
||||
|
||||
def url_for_direct_upload(key, expires_in:, content_type:, content_length:)
|
||||
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
||||
instrument :url, key do |payload|
|
||||
generated_url = bucket.signed_url key, method: "PUT", expires: expires_in,
|
||||
content_type: content_type
|
||||
content_type: content_type, content_md5: checksum
|
||||
|
||||
payload[:url] = generated_url
|
||||
|
||||
|
|
|
@ -59,10 +59,10 @@ class ActiveStorage::Service::S3Service < ActiveStorage::Service
|
|||
end
|
||||
end
|
||||
|
||||
def url_for_direct_upload(key, expires_in:, content_type:, content_length:)
|
||||
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
||||
instrument :url, key do |payload|
|
||||
generated_url = object_for(key).presigned_url :put, expires_in: expires_in,
|
||||
content_type: content_type, content_length: content_length
|
||||
content_type: content_type, content_length: content_length, content_md5: checksum
|
||||
|
||||
payload[:url] = generated_url
|
||||
|
||||
|
|
|
@ -9,14 +9,15 @@ if SERVICE_CONFIGURATIONS[:gcs]
|
|||
|
||||
test "direct upload" do
|
||||
begin
|
||||
key = SecureRandom.base58(24)
|
||||
data = "Something else entirely!"
|
||||
direct_upload_url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size)
|
||||
key = SecureRandom.base58(24)
|
||||
data = "Something else entirely!"
|
||||
checksum = Digest::MD5.base64digest(data)
|
||||
url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum)
|
||||
|
||||
HTTParty.put(
|
||||
direct_upload_url,
|
||||
url,
|
||||
body: data,
|
||||
headers: { "Content-Type" => "text/plain" },
|
||||
headers: { "Content-Type" => "text/plain", "Content-MD5" => checksum },
|
||||
debug_output: STDOUT
|
||||
)
|
||||
|
||||
|
|
|
@ -9,14 +9,15 @@ if SERVICE_CONFIGURATIONS[:s3]
|
|||
|
||||
test "direct upload" do
|
||||
begin
|
||||
key = SecureRandom.base58(24)
|
||||
data = "Something else entirely!"
|
||||
url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size)
|
||||
key = SecureRandom.base58(24)
|
||||
data = "Something else entirely!"
|
||||
checksum = Digest::MD5.base64digest(data)
|
||||
url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum)
|
||||
|
||||
HTTParty.put(
|
||||
url,
|
||||
body: data,
|
||||
headers: { "Content-Type" => "text/plain" },
|
||||
headers: { "Content-Type" => "text/plain", "Content-MD5" => checksum },
|
||||
debug_output: STDOUT
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue