I'm trying to create a file in GCF environment with json2csv and uploading it to Firebase Storage. I'm able to create the file ( I tried to download it to test and the file is good ) but when it comes to upload the file to Firebase, I'm getting an error. I think I'm missing a step or doing something wrong to upload the file.
I also get this error in GCF:
severity: "ERROR" textPayload: "Error: ENOENT: no such file or directory, stat '"a","b" 0,1'"
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
const json2csv = require("json2csv").parse;
exports.csvJsonReport = functions.https.onRequest((request, response) => {
var report = { 'a': 0, 'b': 1 };
const csv = json2csv(report)
const opts = {
destination: 'testfile.csv',
metadata: {
contentType: 'text/csv'
}
};
storage.bucket('Reports').upload(csv, opts)
// response.setHeader(
// "Content-disposition",
// "attachment; filename=report.csv"
// )
// response.set("Content-Type", "text/csv")
// response.status(200).send(csv)
})