Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing publicly while inserting object by Google Cloud Storage JSON API

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?

like image 765
Ashish Awasthi Avatar asked Jan 26 '14 16:01

Ashish Awasthi


People also ask

How do I give public access to GCP bucket?

In the Google Cloud console, go to the Cloud Storage Buckets page. In the list of buckets, click on the name of the bucket that you want to make public. Select the Permissions tab near the top of the page. In the Permissions section, click the + Add button.

How do I share files on Google Cloud?

Select the Share publicly checkbox next to files in your bucket that you want to share. Use the Public link next to the checkbox. Grant project access: Click IAM & Admin in the left side menu and grant users access to your project (and thus to your buckets and files, unless you set specific bucket or file permissions).


1 Answers

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.

like image 70
Brandon Yarbrough Avatar answered Sep 18 '22 16:09

Brandon Yarbrough