Passing extra parameters in ActiveStorage::Blob#url
to S3 Client
This allows calls of `ActiveStorage::Blob#url` to have more interaction with the S3 Presigner, enabling, amongst other options, custom S3 domain URL Generation. Closes #42488
This commit is contained in:
parent
7893428113
commit
302f708729
@ -1,3 +1,18 @@
|
||||
* Passing extra parameters in `ActiveStorage::Blob#url` to S3 Client
|
||||
|
||||
This allows calls of `ActiveStorage::Blob#url` to have more interaction with
|
||||
the S3 Presigner, enabling, amongst other options, custom S3 domain URL
|
||||
Generation.
|
||||
|
||||
```ruby
|
||||
blob = ActiveStorage::Blob.last
|
||||
|
||||
blob.url # => https://<bucket-name>.s3.<region>.amazonaws.com/<key>
|
||||
blob.url(virtual_host: true) # => # => https://<bucket-name>/<key>
|
||||
```
|
||||
|
||||
*josegomezr*
|
||||
|
||||
* Allow setting a `Cache-Control` on files uploaded to GCS.
|
||||
|
||||
```yaml
|
||||
|
@ -96,14 +96,14 @@ def headers_for_direct_upload(key, content_type:, checksum:, filename: nil, disp
|
||||
end
|
||||
|
||||
private
|
||||
def private_url(key, expires_in:, filename:, disposition:, content_type:, **)
|
||||
def private_url(key, expires_in:, filename:, disposition:, content_type:, **client_opts)
|
||||
object_for(key).presigned_url :get, expires_in: expires_in.to_i,
|
||||
response_content_disposition: content_disposition_with(type: disposition, filename: filename),
|
||||
response_content_type: content_type
|
||||
response_content_type: content_type, **client_opts
|
||||
end
|
||||
|
||||
def public_url(key, **)
|
||||
object_for(key).public_url
|
||||
def public_url(key, **client_opts)
|
||||
object_for(key).public_url(**client_opts)
|
||||
end
|
||||
|
||||
|
||||
|
@ -23,6 +23,15 @@ class ActiveStorage::Service::S3PublicServiceTest < ActiveSupport::TestCase
|
||||
assert_equal "200", response.code
|
||||
end
|
||||
|
||||
test "public URL generation (virtual host enabled)" do
|
||||
url = @service.url(@key, filename: ActiveStorage::Filename.new("avatar.png"), virtual_host: true)
|
||||
|
||||
assert_match(/#{@service.bucket.name}\/#{@key}/, url)
|
||||
|
||||
response = Net::HTTP.get_response(URI(url))
|
||||
assert_equal "200", response.code
|
||||
end
|
||||
|
||||
test "direct upload" do
|
||||
key = SecureRandom.base58(24)
|
||||
data = "Something else entirely!"
|
||||
|
Loading…
Reference in New Issue
Block a user