Skip to content

Instantly share code, notes, and snippets.

@bipoza
Forked from n1ru4l/index.js
Last active November 14, 2022 11:35
Show Gist options
  • Save bipoza/b0934f94dd749ca3a0b9a658ec626a35 to your computer and use it in GitHub Desktop.
Save bipoza/b0934f94dd749ca3a0b9a658ec626a35 to your computer and use it in GitHub Desktop.
Fetch blob and convert to base64
export const fetchAsBlob = url => fetch(url)
.then(response => response.blob());
export const convertBlobToBase64 = blob => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
//fetchAsBlob(`https://fonts.gstatic.com/s/roboto/v16/d-6IYplOFocCacKzxwXSOJBw1xU1rKptJj_0jans920.woff2`)
// .then(convertBlobToBase64)
// .then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment