【问题标题】:Firebase web client upload JSON to Cloud StorageFirebase 网络客户端将 JSON 上传到 Cloud Storage
【发布时间】:2020-10-20 04:16:37
【问题描述】:

我正在使用 Firebase 网络客户端,并希望将 JSON 上传到 Cloud Storage。我可以使用firebase.storage().ref().child("/testing.json"); 创建引用,但是我不确定如何上传 JSON 字符串。文档仅提及上传文件、blob 和 base64 编码字符串。 例如,我如何完成以下将JSON字符串上传到云存储,存储为“application/json”内容类型的JSON文件?

const ref = firebase.storage().ref().child("/testing.json");
const jsonString = JSON.stringify({ hello: "world" });
ref.put() // ???

【问题讨论】:

    标签: javascript json firebase google-cloud-storage


    【解决方案1】:

    Storage ref put 可以采用 Blob 参数。将字符串转换为 blob...

    const ref = firebase.storage().ref().child("/testing.json");
    const jsonString = JSON.stringify({ hello: "world" });
    
    const blob = new Blob([jsonString], { type: 'application/json' });
    ref.put(blob).then( ... )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-21
      • 2019-04-08
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 2013-01-09
      • 2021-03-19
      • 1970-01-01
      相关资源
      最近更新 更多