簡體   English   中英

Firebase 函數保存 JSON 到本地文件

[英]Firebase functions saving JSON to local file

我有一個 firebase 函數,我在其中創建了一個 JSON:

var tempJSONObject = {
  testing: "why are we testing",
  anothertest:"constanttesting"
}

我有一個臨時文件:

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

如何將我的 JSON 保存到這個臨時文件,以便我可以將文件上傳到 firebase 存儲? 我必須這樣做,因為當我將 JSON 直接傳遞給 bucket.upload() 時,它要求我提供文件路徑。

您根本不需要將其保存到文件中。 您可以簡單地使用JSON.stringify()將 object 字符串化,然后使用File.createWriteStream()將該字符串上傳到存儲桶,將字符串值直接寫入提供的 stream。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM