I have a Blob object I want to inspect by logging its value. All I can see are type
and size
properties. Is there a way to do this?
Basic example on using a FileReader to look at the content in a blob
var html= ['<a id="anchor">Hello World</a>']; var myBlob = new Blob(html, { type: 'text/xml'}); var myReader = new FileReader(); myReader.onload = function(event){ console.log(JSON.stringify(myReader.result)); }; myReader.readAsText(myBlob);
First of all we should create a function for converting blob to base64:
const blobToBase64 = blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
return new Promise(resolve => {
reader.onloadend = () => {
resolve(reader.result);
};
});
};
Then we can use this function to use it for console.log
:
blobToBase64(blobData).then(res => {
console.log(res); // res is base64 now
// even you can click on it to see it in a new tab
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.