我正在尝试将一个简单的测试文件从我的工作目录上传到 firebase 存储。为此,我创建了以下代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.Storage = functions.https.onCall((data, context) => {
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('myapp.appspot.com');
const options = {
destination: 'Test_Folder/hello_world.dog'
};
bucket.upload('./tst.txt', options).then(function(data) {
const file = data[0];
if (file) {
return file;
}else{
throw new Error("Irgendwas geht ned")
}
}).catch(e);
return 200;
});
不幸的是,firebase 总是说:
错误:ENOENT:没有这样的文件或目录,stat '/tst.txt'
我的文件位于我的项目中的 ./tst.txt 我的目标是在我的 cloudfunction 中生成一个文本文件并将它们上传到 firebase 存储来存储它。当前没有文件存储在存储中。现在我希望能够上传已经创建的文件。这是我的文件的组织方式:
