是否有任何支持的方式将Firebase服务帐户写入您的云存储桶? [英] Is there any supported way for a firebase service accounts to write to your cloud storage buckets?
本文介绍了是否有任何支持的方式将Firebase服务帐户写入您的云存储桶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 用户上传照片
- 服务器将照片转换成缩略图,中等,高清,并将文件写入用户目录。 google.com/docs/reference/android/com/google/firebase/storage/package-summaryrel =nofollow>这个API,但对于 server module:
- User uploads photo
- Server transforms that photo into thumbnail, medium, high definition and writes the files to the users directory.
解决方案
存储由Google云端存储支持,因此我们建议您通过 gcloud-node 使用Google云端存储:
//导入gcloud
var gcloud = require('gcloud');
//用服务帐户初始化
var gcs = gcloud.storage({
projectId:'my-project',
keyFilename:'/ path / to /keyfile.json'
});
//引用现有的存储桶。
var bucket = gcs.bucket('< projectid> .appspot.com');
//将本地文件上传到要在您的存储桶中创建的新文件。
bucket.upload('/ photos / zoo / zebra.jpg',函数(err,file){
if(!err){
//zebra.jpg现在处于你的桶。
}
});
//从您的存储桶下载文件。
bucket.file('giraffe.jpg')。download({
destination:'/photos/zoo/giraffe.jpg'
},function(err){});
还有其他的Python,Java,Go,Ruby等gcloud模块。这里。
As a contrived example:
Similar to this API but for the server module:
解决方案
Since Firebase Storage is backed by Google Cloud Storage, we recommend using Google Cloud Storage through gcloud-node for this:
// Import gcloud
var gcloud = require('gcloud');
// Initialize with a service account
var gcs = gcloud.storage({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Reference an existing bucket.
var bucket = gcs.bucket('<projectid>.appspot.com');
// Upload a local file to a new file to be created in your bucket.
bucket.upload('/photos/zoo/zebra.jpg', function(err, file) {
if (!err) {
// "zebra.jpg" is now in your bucket.
}
});
// Download a file from your bucket.
bucket.file('giraffe.jpg').download({
destination: '/photos/zoo/giraffe.jpg'
}, function(err) {});
There are other gcloud modules for Python, Java, go, ruby, etc. here.
这篇关于是否有任何支持的方式将Firebase服务帐户写入您的云存储桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文