0
votes

I have a firebase function which tries to write data to firebase storage:

const bucket = admin.storage().bucket(/*removed for this question*/);
var tempJSONObject = {
 testing: "why are we testing",
 anothertest:"constanttesting"
}
try{
const fileName = `storedjokes/81.json`
const file = bucket.file(fileName);
const writeStream = fs.createWriteStream(file);
writeStream.write(tempJSONObject,(err) => {
 if(err){
   console.log(err.message);
 }else{
   console.log("data written");
 }
});
}catch(e){
 console.log('error',e);
}

I get a error in the firebase logs which says:

error TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type object

How do I fix this?

1

1 Answers

0
votes

The error message is pretty explicit: you can only write a string (or the path to a file), a buffer, or URL to a write stream.

If you want to write the literal string representation of your JSON object to the file, you'll have to convert the object to a string with JSON.stringify(tempJSONObject).