firebase 服务帐户是否有任何支持的方式写入您的云存储桶?
Is there any supported way for a firebase service accounts to write to your cloud storage buckets?
举个例子:
- 用户上传照片
- 服务器将该照片转换为缩略图、中、高清并将文件写入用户目录。
由于 Firebase 存储由 Google 云存储支持,因此我们建议通过 gcloud-node 使用 Google 云存储:
// 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) {});
Python、Java、go、ruby 等还有其他 gcloud 模块。here。
举个例子:
- 用户上传照片
- 服务器将该照片转换为缩略图、中、高清并将文件写入用户目录。
由于 Firebase 存储由 Google 云存储支持,因此我们建议通过 gcloud-node 使用 Google 云存储:
// 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) {});
Python、Java、go、ruby 等还有其他 gcloud 模块。here。