Hi I am trying to upload a base 64 file from NodeJs to firebase storage(google cloud storage) using the below given code. But I am getting an error stating
Error here TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object at validateString (internal/validators.js:125:11)
the code is:
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'));})
Can someone suggest me a way out? I can't understand the problem. Thanks