2

In the Amazon S3 SDK, when generating a presigned URL, I can generate a URL setting the content-disposition, but I cannot find a similar way of configuring these options using Google.

The method call available to us is:

https://www.rubydoc.info/gems/google-cloud-storage/0.20.0/Google/Cloud/Storage/File#signed_url-instance_method

I am trying to upload a file directly to a Google bucket and not via my Rails server, and want to set the content-disposition of the file being uploaded via the presigned URL. Is there a way of doing this? Is there a way of setting object meta data via a presigned URL?

require "google/cloud"

gcloud = Google::Cloud.new
storage = gcloud.storage

bucket = storage.bucket "my-todo-app"
file = bucket.file "avatars/heidi/400x400.png"
shared_url = file.signed_url
# The parameters it takes is: signed_url(method: nil, expires: nil, content_type: nil, content_md5: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil)

# how do we add content_disposition?
# how do we add object meta data?
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
BenKoshy
  • 33,477
  • 14
  • 111
  • 80

1 Answers1

1

I'm looking for the same answer, and so far I have found this other Stack Overflow article, which doesn't directly address Ruby SDK, but it does offer a good piece of information.

Google Cloud Storage: download a file with a different name

You can also generate signed URLs that include the response-content-disposition query parameter. Then the users will be making authorized requests to download the resource.

So it appears that you can add the query parameter ?response-content-disposition=[disposition-string-urlencoded] to the resulting signed string.

So, I looked at the File object definition in the Ruby SDK and it appears you can do this:

file.content_dispostion = "attachment" # or whatever your disposition is
url = file.signed_url

NOTE: If you read my entry before I edited it, my apologies.

Jocko
  • 537
  • 2
  • 11
  • 1
    Here's the File#content_disposition definition in the documentation for your reference: https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#content_disposition=-instance_method – Jocko May 30 '20 at 00:43
  • Any luck with this solution? – Jocko Jun 01 '20 at 20:21
  • oh dear i may have missed the edit, but i appreciate your answer. in the end, i gave up and just ran with the AWS's `s3` offering. probably a good decision in the end: GCS has too many issues regarding its uptime, and API is less developed than AWS. – BenKoshy Jan 05 '22 at 02:13