node.js - 如何访问谷歌云存储中的对象?

标签 node.js google-cloud-storage axios

我正在尝试构建一个应用程序,该应用程序将在存储桶私有(private)时访问我的谷歌云存储中的文件。文档不清楚如何才能从服务器访问存储桶。我有他们提供的 json 文件。我计划使用 nodejs 公开存储桶上的文件,但我不确定如何授权对存储桶的请求。顺便说一下,我正在使用 axios。我是创建 API key 还是使用 key 作为查询字符串?一些帮助将不胜感激!

最佳答案

您需要 Google Cloud 的 Node.JS 库:https://googlecloudplatform.github.io/google-cloud-node/#/

下面是一个使用它来访问 GCS 中的对象的示例:

var config = {
  projectId: 'grape-spaceship-123',
  keyFilename: '/path/to/keyfile.json'
};
var storage = require('@google-cloud/storage')(config);

var bucket = gcs.bucket('my-existing-bucket');
var remoteReadStream = bucket.file('giraffe.jpg').createReadStream();
remoteReadStream.pipe(someLocalWriteStream);

GitHub 页面上还有其他几个示例:https://github.com/GoogleCloudPlatform/google-cloud-node#preview-1

以及此处的大量文档: https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.56.0/storage

关于node.js - 如何访问谷歌云存储中的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45331443/

相关文章:

android - 从服务器发送通知时,remoteMessage.getNotification() 始终为 null - Android

javascript - POST 请求中缺少字段是否会引发错误?

javascript - 如何使用 axios 编写 redux 异步操作的测试用例?

javascript - (0 , _axios.default) 在使用拦截器模拟 axios 时不是函数

javascript - Python:发送 JSON 数据时使用 POST 请求的 FastAPI 错误 422

javascript - 从嵌套 JSON 中获取值

node.js - 查找未邀请任何用户的用户

node.js - 使用meteor将图像文件从google云存储桶下载到IOS localstorage

google-app-engine - 提供来自 Google Cloud Storage 的静态 SPA 和来自 Google App Engine 的 API

google-cloud-storage - Google Cloud Storage 中元数据值的长度有限制吗?