如何访问谷歌云存储中的对象? [英] How to access objects in google cloud storage?

查看:256
本文介绍了如何访问谷歌云存储中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个应用程序,该应用程序将在存储桶为私有时访问我的Google云存储中的文件.文档未明确如何执行操作以允许从服务器访问存储桶.我有他们提供的json文件.我计划使用nodejs公开存储桶中的文件,但是我不确定如何授权对存储桶的请求.我正在使用axios.是否创建API密钥或将密钥用作查询字符串?一些帮助,将不胜感激!

I am trying to build an application that will access files in my google cloud storage while the bucket is private. The docs arent clear on what to do to enable access of the bucket from a server. I have the json file which they provide. I plan on using to expose the files on the bucket using nodejs but I'm not sure how to authorize requests to the bucket. I am using axios by the way. Do i create an API key or use a key as a query string? Some help would be appreciated!

推荐答案

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

You want Google Cloud's Node.JS library: https://googlecloudplatform.github.io/google-cloud-node/#/

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

Here's an example of using it to access an object in 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

There are several other examples on the GitHub page: https://github.com/GoogleCloudPlatform/google-cloud-node#preview-1

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

As well as extensive documentation here: https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.56.0/storage

这篇关于如何访问谷歌云存储中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆