【问题标题】:Google Cloud Storage API and Node.js谷歌云存储 API 和 Node.js
【发布时间】:2014-08-29 00:23:03
【问题描述】:

我正在尝试使用 node.js 客户端库来访问 googleAPI (https://github.com/google/google-api-nodejs-client)。 我正在尝试使用谷歌云存储 API 插入存储桶和对象。我可以成功列出我项目存储的存储桶。也可以从存储中检索特定的桶。但无法插入桶或对象。

执行 API 调用的代码:

 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);
                                 });

这是日志中显示的内容:

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

任何指示什么是“必需”,如何提供?

【问题讨论】:

    标签: node.js google-cloud-storage google-api-client google-api-nodejs-client


    【解决方案1】:

    资源对象应作为.insert 的第二个参数,如下所示:

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

    【讨论】:

    • 有插入对象的例子吗?我正在尝试将简单的文本对象插入到存储桶中。但在日志中显示相同的错误消息:'Required'。
    • 您需要使用 withMedia 将对象和元数据上传到存储桶。如何在此处使用 .withMedia 的示例:github.com/google/google-api-nodejs-client/blob/master/examples/…
    • 哇..它有效。非常感谢。我是 node.js 的新手,完全不知道该怎么做。谢谢瑞恩。
    猜你喜欢
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2014-08-11
    • 2019-03-22
    • 2018-09-18
    • 2020-09-22
    相关资源
    最近更新 更多