Node.js Firebase函数将JSON保存到本地文件

Node.js Firebase函数将JSON保存到本地文件,node.js,firebase,google-cloud-functions,google-cloud-storage,Node.js,Firebase,Google Cloud Functions,Google Cloud Storage,我有一个firebase函数,其中我创建了一个JSON: var tempJSONObject = { testing: "why are we testing", anothertest:"constanttesting" } 我有一个临时文件: const tempFilePath = path.join(os.tmpdir(), data.jokeid); 如何将JSON保存到此临时文件,以便将文件上载到firebase存储?我必须这样

我有一个firebase函数,其中我创建了一个JSON:

var tempJSONObject = {
  testing: "why are we testing",
  anothertest:"constanttesting"
}
我有一个临时文件:

 const tempFilePath = path.join(os.tmpdir(), data.jokeid);

如何将JSON保存到此临时文件,以便将文件上载到firebase存储?我必须这样做,因为当我将JSON直接传递给bucket.upload()时,它会要求我提供一个文件路径。

您根本不需要将其保存到文件中。您只需使用字符串化对象,然后使用将该字符串上载到bucket,将字符串值直接写入提供的流。

是否有比File.createWriteStream()更多的内容?如何指定要写入的文件和要上载的文件?我链接到的API文档包含了您需要的所有内容,包括一个示例。它非常灵活,您需要理解nodejs流。当我使用JSON.stringify()并传递我得到的消息时:“path”参数必须是string、Buffer或URL类型之一。Received type Objective如果您有新问题,请单独发布,显示未按预期方式运行的新代码。