我正在使用 Firebase Web 客户端并希望将 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() // ???
最佳答案
存储引用放置可以采用 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( ... )
关于javascript - Firebase Web 客户端将 JSON 上传到 Cloud Storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62647645/