3

I am using the Firebase web client and would like to upload JSON to Cloud Storage. I can create a reference using firebase.storage().ref().child("/testing.json");, however I am not sure how to upload the JSON string. The docs only mention uploading files, blobs, and base64 encoded strings. For example, how do I finish the below to upload to the JSON string to cloud storage, to be stored as a JSON file with "application/json" content type?

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

1 Answer 1

4

Storage ref put can take a Blob parameter. Convert the string to a 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( ... )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.