【发布时间】:2020-09-26 22:22:37
【问题描述】:
一段时间以来,我一直在尝试创建一个包含一些文本(hello world)的文件(sample.txt),最后将其上传到存储桶中。有没有办法我可以实现这个?我尝试的代码如下:
exports.uploadFile = functions.https.onCall(async (data, context) => {
try {
const tempFilePath = path.join(os.tmpdir(), "sample.txt");
await fs.writeFile(tempFilePath, "hello world");
const bucket = await admin.storage().bucket("allcollection");
await bucket.upload(tempFilePath);
return fs.unlinkSync(tempFilePath);
} catch (error) {
console.log(error);
throw new functions.https.HttpsError(error);
}
});
无论何时运行此代码,我都会在 firebase 控制台中得到类似这样的错误:
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:128:9)
at Object.writeFile (fs.js:1163:14)
【问题讨论】:
-
请编辑问题以解释您现在拥有的代码到底有什么问题,包括您拥有的任何调试信息。我建议阅读stackoverflow.com/help/minimal-reproducible-example
-
我一定会这样做的
标签: javascript node.js firebase google-cloud-functions google-cloud-storage