Skip to content

Instantly share code, notes, and snippets.

@ccwq
Created March 20, 2020 06:32
Show Gist options
  • Save ccwq/de38a651cb36f2675b89b6a33d837e0a to your computer and use it in GitHub Desktop.
Save ccwq/de38a651cb36f2675b89b6a33d837e0a to your computer and use it in GitHub Desktop.
js 文件各种转换
/**
* blobURL2blob
* @param blobURL
* @returns {Promise<any>}
*/
export function blobURL2blob(blobURL){
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open('GET', blobURL, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
resolve(this.response);
// var myBlob = this.response;
// // myBlob is now the blob that the object URL pointed to.
}else{
reject(this)
}
};
xhr.onerror = reject;
xhr.send();
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment