4

I've searched everywhere on this but I cannot find a solution, how can I upload a public object to my google cloud storage, I want to have it so once the image is uploaded it can be viewed by anyone in the world.

It seems I can only get this done if I manually click the public link in google storage, but I want to have it so I can automatically make these objects public through googles api . enter image description here

Errol Green
  • 1,367
  • 5
  • 19
  • 32
  • This post may help you. Good luck! http://stackoverflow.com/questions/30417893/setting-an-object-to-shared-public-url-when-inserting-into-google-cloud-storage?answertab=active#tab-top – Nguyen Minh Hien Apr 04 '17 at 00:56

1 Answers1

4

The web interface doesn't provide a way to make the objects being uploaded public automatically, but you can do one of two things:

  1. If you want to just make objects publicly readable during one particular session you could use gsutil to do it, e.g.,

    gsutil -m cp -a public-read dir/* gs://your-bucket

  2. If you want to make objects publicly readable across all future sessions you could set a default object ACL on the bucket, using a command like:

    gsutil defacl set public-read gs://your-bucket

If you do that, uploads via the web interface (as well as by any other API requests, e.g., gsutil cp commands) will be made publicly readable automatically.

Mike Schwartz
  • 11,511
  • 1
  • 33
  • 36
  • does that apply to the entire directory, is that just a one time use or once that is set on the directory all objects loaded after will be public-read? – Errol Green Aug 06 '15 at 23:32
  • 1
    The command is copying all the files in 'dir', and uploading it to 'your-bucket' with each individual file being public-read. If you want to upload more files, you have to mark them "public-read" as well. I also recommend using the -m flag if you are uploading multiple files at once. – Sandeep Dinesh Aug 07 '15 at 00:14
  • @SandeepDinesh Thanks for the clarification, I was unsure exactly how it was being used. I understand fully now and was able to resolve my issue. – Errol Green Aug 07 '15 at 00:21
  • I added setting a default object ACL on the bucket to my answer, since that provides a way to do it that would work with the web interface. – Mike Schwartz Aug 07 '15 at 17:53