I know this is an old question, but I came across this problem lately and it took me a while to fix it. So I am going to answer the question in case anyone run into it again.
First, I think the naming of variable blob
is very confusing. Blob URLs and Blob Object are different things. This answer does a very good job explaining what a Blob URL is. I think you should rename it as below.
var blobUrl = 'blob:http://localhost:3000/e3c2...'
Then, the function readAsDataURL
of FileReader
requires a Blob Object as its parameter. And what you give it is the variable blob
, which is a Blob URL.
So what you need to do is:
- Recover the Blob Object that is used to create the Blob URL
- Use
readAsDataURL
to convert the recovered Blob Object to base64 url
Here is the code I find in this answer:
var blob = new Blob(["Hello, world!"], { type: 'text/plain' });
var blobUrl = URL.createObjectURL(blob);
var xhr = new XMLHttpRequest;
xhr.responseType = 'blob';
xhr.onload = function() {
var recoveredBlob = xhr.response;
var reader = new FileReader;
reader.onload = function() {
var blobAsDataUrl = reader.result;
window.location = blobAsDataUrl;
};
reader.readAsDataURL(recoveredBlob);
};
xhr.open('GET', blobUrl);
xhr.send();