Skip to content

ApiError: Insufficient Permission even when the same API wrote the file to Storage #1017

@ajpyoung

Description

@ajpyoung

I'm at a loss here. My node code successfully uploaded files to gcloud Storage but can't seem to make the file public or even change the acl.

The error returned is

{ [ApiError: Insufficient Permission]
errors:
 [ { domain: 'global',
     reason: 'insufficientPermissions',
     message: 'Insufficient Permission' } ],
code: 403,
message: 'Insufficient Permission',
response: undefined }

Here's my code

var gcs = GLOBAL.gcloud.storage();
var bucket = gcs.bucket(GLOBAL.storage_names.products);
var file = bucket.file('images/'+targetValue+'_'+filename);
stdout.pipe(file.createWriteStream())
  .on('error', function(err) {
    var msg = {
      "status":"Error"
      "err":err
    };
    console.log(msg);

  })
  .on('finish', function() {
    // The file upload is complete.
    console.log("Successfully uploaded "+targetValue+'_'+filename);
    file.acl.add({
      entity: 'allUsers',
      role: gcs.acl.READER_ROLE
    }, function(err, aclObject) {

      if(err==null)
      {
        //stream upload file
        file.makePublic();
      }else{
        console.log("ERROR in ACL Adding");
        console.log(err)
      }

    });
    file.makePublic(function(err, apiResponse) {
      if(err==null)
      {
        console.log("File made public");
      }else{
        console.log("make public error");
        console.log(err);
      }
    });
  });

Metadata

Metadata

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions