0

我正在尝试将一个简单的测试文件从我的工作目录上传到 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 存储来存储它。当前没有文件存储在存储中。现在我希望能够上传已经创建的文件。这是我的文件的组织方式: 文件树

4

1 回答 1

1

Firebase CLI 将部署函数文件夹中的所有文件,node_modules 除外。您的 tst.txt 文件不在其中 - 它高一个文件夹。所以它甚至没有被部署。您必须将其移动到函数中才能使其在运行时对函数可用。

于 2020-06-29T21:36:21.227 回答