turn blob into text and do reverse function later

2

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

    
asked by anonymous 08.03.2015 / 15:57

1 answer

2

You can use FileReader.readAsDataURL , it encodes Blob in base64. On your server, you can then decode from base64 to binary again (you did not specify the language, but they all have routines ready to do this):

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

Font

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

    
08.03.2015 / 16:44