3

I need to create and share a bucket in gcloud storage using Node.js Client.

This is my code

 Bucket.createNewBucket = function (request, callBack) {
    // code for create a new bucket
    var bucketName = request.body.bucketName;

    gcs.createBucket(bucketName, function (err, bucket) {
        if (!err) {
            console.log("created bucket successfully");
            var bucketadded = gcs.bucket(bucketName);
            bucketadded.acl.add({
                entity: 'testmail@gmail.com',
                role: 'READER'
            }, function (err, aclObject) {
                if (!err) {console.log("acl added successfully");
                }else{
                    console.log(err);
                }
             });
            callBack(null, true);
            return;
        } else {
            callBack("Error with bucket creation. Error: " + err, true);
            return;
        }
    });
};

Using this code, I am successfully able to create a bucket in google storage. But I can't add acl permission to the bucket.

i got error like this

{ [ApiError: Invalid Value]
  errors: [ { domain: 'global', reason: 'invalid', message: 'Invalid Value' } ],
  code: 400,
  message: 'Invalid Value',
  response: undefined }
Ash
  • 6,483
  • 7
  • 29
  • 37
Abdul Manaf
  • 4,933
  • 8
  • 51
  • 95

2 Answers2

3

use this

entity: 'user-testmail@gmail.com'

instead of

entity: 'testmail@gmail.com'
1

Entity is more complex than just an email address. In this case, the proper value would be "user-manafcj@gmail.com". There are other categories for groups, as well as some special values like "AllUsers".

It's documented here: https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/insert

Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145