transform blob into text and do reverse function later

Asked

Viewed 62 times

2

I am using a script that results audio/video in blob format, you need to upload it BUT I would like to turn it into text so that the execution of a function the part does not harm. And when it arrives on the server and returns to a user who is done the reverse effect by turning the text into blob again for the user to have access to media, is it possible to do this? as?

1 answer

2


You can use FileReader.readAsDataURL, he codes the Blob in Base64. On your server, you can then decode from Base64 to binary again (you haven’t specified the language, but all of them often have routines ready to do so):

var reader = new window.FileReader();
reader.readAsDataURL(blob); 
reader.onloadend = function() {
    var base64data = reader.result;                
    console.log(base64data);
}

Source

Note: before data in Base64, there may be meta-data on read content, for example data:image/png;base64,iVBORw0KGgoA...; the content therefore is that after base64, - use only that part when decoding on the server (unless the function used knows how to handle data urls).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.