Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to wget / curl protected files from GCS?

Is it possible to wget / curl protected files from Google Cloud Storage without making them public? I don't mind a fixed predefined token. I just want to avoid the case where my public file gets leeched, costing me good dollars.

like image 766
codefx Avatar asked Mar 21 '16 07:03

codefx


People also ask

How do I download using Gsutil?

Google Cloud Storage also offers the gsutil tool that makes the full functionality of these APIs available through a convenient command line interface. As noted above, right-clicking on files and selecting "Save as" will do the trick, as should simply left clicking files.

What is blob in GCP?

Blobs are useful for serving large files, such as video or image files, and for allowing users to upload large data files. Blobs are created by uploading a file through an HTTP request. Typically, your applications will do this by presenting a form with a file upload field to the user.


3 Answers

Another way, if as you say you don't mind getting a token externally, is to use curl to set the 'Authorization' header in your call to GCS like so:

curl -H "Authorization: Bearer 1/fFBGRNJru1FQd44AzqT3Zg" https://www.googleapis.com/storage/v1/b/bucket/o/object?alt=media

The 'alt=media' query string parameter is necessary to download the object data directly instead of receiving a JSON response.

You can copy and paste the token obtained by authorizing with the Cloud Storage JSON API separately in the OAuth 2.0 Playground.

See also:
https://cloud.google.com/storage/docs/access-control https://cloud.google.com/storage/docs/json_api/v1/objects/get

like image 146
Adam Avatar answered Oct 20 '22 09:10

Adam


You could also use the curlwget chrome extension so whenever you download something on Chrome it will create the url with headers etc to allow you to wget your file.

like image 29
Scott Condron Avatar answered Oct 20 '22 07:10

Scott Condron


You can use Signed URLs. This allows you to create a signed URL that can be used to download an object without additional authentication.

like image 45
jterrace Avatar answered Oct 20 '22 08:10

jterrace