【发布时间】:2018-11-07 18:29:11
【问题描述】:
download() 的 Google Cloud Storage documentation 建议可以指定目标文件夹:
file.download({
destination: '/Users/me/Desktop/file-backup.txt'
}, function(err) {});
无论我在文件中输入什么值,始终会在根级别下载到 Firebase Cloud Storage。这个question 表示路径不能有初始斜杠,但将示例更改为
file.download({
destination: 'Users/me/Desktop/file-backup.txt'
}, function(err) {});
没有区别。
将目的地更改为
file.download({
destination: ".child('Test_Folder')",
})
导致错误信息:
EROFS: read-only file system, open '.child('Test_Folder')'
云存储destination(文件夹和文件名)的正确语法是什么?
将存储桶从 myapp.appspot.com 更改为 myapp.appspot.com/Test_Folder 导致错误消息:
Cannot parse JSON response
此外,示例路径似乎指定了个人计算机硬盘驱动器上的位置。为Desktop 设置云存储文件夹似乎很奇怪。这是否意味着有一种方法可以在 Cloud Storage 以外的地方指定目的地?
这是我的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.Storage = functions.firestore.document('Storage_Value').onUpdate((change, context) => {
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('myapp.appspot.com');
bucket.upload('./hello_world.ogg')
.then(function(data) {
const file = data[0];
file.download({
destination: 'Test_Folder/hello_dog.ogg',
})
.then(function(data) {
const contents = data[0];
console.log("File uploaded.");
})
.catch(error => {
console.error(error);
});
})
.catch(error => {
console.error(error);
});
return 0;
});
【问题讨论】:
标签: firebase google-cloud-storage google-cloud-functions firebase-storage