简体   繁体   中英

Google Cloud Storage API and Node.js

I am trying to work with node.js client library for accessing googleAPI ( https://github.com/google/google-api-nodejs-client ). I am trying to insert bucket and object using google cloud storage API. I can successfully list the buckets of my project's storage. Also can retrieve specific bucket from the storage. But unable to insert the bucket or object.

Code which do the API call:

 googleapis.discover('storage', 'v1').execute(function(err,client){
    if(err)
     {
         console.log(err);
     }
  //insert bucket
  client.storage.buckets.insert({'project': "myproject_id",
                                 'resource': {'name': "mystorage-bucket"}})
                                  .withAuthClient(auth)
                                  .execute(function(err,result){
                                  console.log('error :',err,'inserted:',result);
                                 });

This is what shows in the log:

    error : { errors: 
                    [ { domain: 'global', 
                        reason: 'required', 
                        message: 'Required' } ],
              code: 400,
              message: 'Required' } inserted: null

Any indication what is "Required", how to provide it?

The resource object should go as the second parameter of .insert like so:

client.storage.buckets.insert({ 
  'project': "myproject_id"
},
{
  'name': "mystorage-bucket"
}).withAuthClient(auth).execute(callback);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM