2

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)
    })
Joris
  • 697
  • 2
  • 9
  • 24
  • Are you able to get the generated filename from `json2csv`? What if you tried uploading using the filename instead as opposed to `csv`? Also, the `.upload()` method is asynchronous so you either have to `await` it or use `.then()` – JKleinne Dec 29 '19 at 16:26
  • This does not work because `upload()` takes a `filePath` as the first parameter (not the file itself). I am looking for a solution as well. – Cooper Scott May 21 '21 at 21:47

0 Answers0