node.js - 无法使用 NodeJS API 将元数据附加到 Google Cloud Storage

标签 node.js google-cloud-platform google-cloud-storage

我指的是将文件上传到 Google Cloud Storage 的以下代码 https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/3-binary-data/lib/images.js#L48

我能够成功上传,现在我正在尝试将元数据添加到文件中,所以我修改了如下代码

  const stream = file.createWriteStream({
    metadata: {
      contentType: req.file.mimetype,
      foo: 'bar'
    }
  });

但是 foo=bar 元数据没有附加到 Google Cloud Storage 中的文件

最佳答案

如果您想将元数据附加到文件,则需要将该数据保存在元数据下。将您的代码更改为以下内容

const stream = file.createWriteStream({
    metadata: {
      contentType: req.file.mimetype,
      metadata: {
        foo: 'bar'
      }
    }
});

关于node.js - 无法使用 NodeJS API 将元数据附加到 Google Cloud Storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47549434/

相关文章:

java - Firebase getDownloadUrl 不执行 onSuccess 或 onFailure

javascript - 使用selenium使用xpath输入多个元素

node.js - 如何从package.json生成component.json?

firebase - CircleCI 工作流程找不到 Firebase 项目 : Invalid project selection please verify project 'project' exists and you have access

google-cloud-platform - CloudSQL 实例必须与查询连接位于同一项目中

json - 无法通过其 mediaLink 从 Google Cloud Storage 检索对象

javascript - 针对字符串测试子字符串数组

node.js - 如何在 Windows 和 Unix 上运行 npm sh 脚本

mongodb - 将 MongoDB 部署到 Google Cloud Platform 的最佳方式?

google-cloud-storage - 谷歌云平台 API -> "The OAuth client was deleted."错误