通用功能:
function urlContentToDataUri(url){
return fetch(url)
.then( response => response.blob() )
.then( blob => new Promise( callback =>{
let reader = new FileReader() ;
reader.onload = function(){ callback(this.result) } ;
reader.readAsDataURL(blob) ;
}) ) ;
}
//Usage example:
urlContentToDataUri('http://example.com').then( dataUri => console.log(dataUri) ) ;
//Usage example using await:
let dataUri = await urlContentToDataUri('http://example.com') ;
console.log(dataUri) ;
标签:dataUri,urlContentToDataUri,base64,fetch,API,blob,reader,example
From: https://www.cnblogs.com/waw/p/16739599.html