【发布时间】:2021-01-05 20:00:50
【问题描述】:
您好,我正在尝试使用以下给定代码将 base 64 文件从 NodeJs 上传到 firebase 存储(谷歌云存储)。但我收到一个错误说明
此处出现错误 TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须 是字符串类型。在 validateString 处接收到类型对象 (内部/validators.js:125:11)
代码是:
const key = require('../key.json');
const {Storage} = require('@google-cloud/storage');
//var gcs = require('@google-cloud/storage');
exports.uploadVideo = functions.https.onRequest((req, res) => {
const gcs =new Storage({
projectId: "<my-project-id>",
keyFilename: key
});
const bucket = gcs.bucket("example.appspot.com");
const gcsname = 'test.pdf';
const file = bucket.file(gcsname);
var pdfdata = "xNC9YUmVmU3RtIDE1NzQ+Pg0Kc3RhcnR4cmVmDQoyMTY5DQolJUVPRg==";
var buff = Buffer.from(pdfdata, 'binary').toString('utf-8');
const stream = file.createWriteStream({
metadata: {
contentType: 'application/pdf'
}
});
stream.on('error', (err) => {
console.log("Error here",err);
});
stream.on('finish', () => {
console.log(gcsname);
});
stream.end(new Buffer.from(buff, 'base64'));})
有人可以建议我出路吗?我无法理解这个问题。 谢谢
【问题讨论】:
-
你能提供你的 package.json 文件吗?
-
@google-cloud/storage 已安装。如果您想寻找其他内容,我可以发布它。
-
@waseemTahir 你明白了吗?我也有同样的问题...
-
@Lion789 不,很遗憾我做不到,而且我的截止日期很紧,所以我在前端实现了它,没有进一步浪费我的时间。
-
感谢您的回复,是的,我只是忽略了使用带有 gcloud 的 winston
标签: node.js firebase google-cloud-functions google-cloud-storage firebase-admin