js stringfy blob code example
Example 1: javascript stringify blob
const blobToBase64 = (blob) => {
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function () {
resolve(reader.result);
};
});
};
(async () => {
const b64 = await blobToBase64(blob);
const jsonString = JSON.stringify({blob: b64});
console.log(jsonString);
})();
Example 2: javascript stringify blob
const parsed = JSON.parse(jsonString);
const blob = await fetch(parsed.blob).then(res => res.blob());
console.log(blob);