嗨,我正在尝试使用以下给定代码将Base64文件从NodeJs上传到Firebase存储(Google云存储)。但是我收到一个错误提示
此处错误TypeError [ERR_INVALID_ARG_TYPE]:“ path”参数必须 是字符串类型。在validateString处收到的类型对象 (internal / 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'));})
有人可以建议我出路吗?我不明白这个问题。 谢谢
答案 0 :(得分:1)
错误显示为“ TypeError [ERR_INVALID_ARG_TYPE]:“ path”参数必须为字符串类型。收到的未定义”
它试图从路径中获取,您应该在寻找路径时将这些变量添加到.env文件中的根目录中。.它会获取正确的变量。让我知道您是否还有困难。.
您可以参考Express Routing with Google Cloud Functions以获得更多详细信息。
答案 1 :(得分:0)
这意味着程序期望path
自变量的类型为string
,例如:"path/to/whatever"
。而您给它一个对象-例如:{ path: "path/to/whatever" }