Skip to content

Instantly share code, notes, and snippets.

@tnightingale
Created November 25, 2015 22:46
Show Gist options
  • Save tnightingale/6851951006f9bd887460 to your computer and use it in GitHub Desktop.
Save tnightingale/6851951006f9bd887460 to your computer and use it in GitHub Desktop.
/**
* TODO: Need to add error handling and then submit pull request to 'blob-util'
* library.
*/
export function objectURLToBlob(url) {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onreadystatechange = () => {
if (xhr.DONE !== xhr.readyState) return;
resolve(xhr.response);
}
xhr.send();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment