7
votes

I am inserting images using Google Cloud Storage JSON API as shown in this sample, that needs to be shared publicly with read permissions. HTTP request looks like this:

      var request = gapi.client.request({
      'path': '/upload/storage/v1beta2/b/' + BUCKET + '/o',
      'method': 'POST',
      'params': {'uploadType': 'multipart'},
      'headers': {'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'},
      'body': multipartRequestBody});

My bucket already has 'Reader' permission for 'All Users', but inserted objects don't inherit that property. Following URL throw access denied till I click on 'Share Publicly' checkbox. http://commondatastorage.googleapis.com/bucketname%2Ffilename

I need those image to be available as soon as inserted. Is there a way to share as part of HTTP insert request?

1

1 Answers

7
votes

There is a property that represents the default permissions of objects created in a bucket, but it's not the bucket permissions. Buckets have a separate property for this purpose called the "default object ACL." If you set this property to public-read, newly created objects will be publicly readable.

If you have gsutil, you can easily set this property to public read like so:

gsutil defacl set public-read gs://mybucket

Alternately, you could modify your call to explicitly set the permissions. Part of your multipart upload is presumably a JSON description of the object being created. One of those properties is "acl", which you can set however you like.