Reference: FileReader.readAsDataURL
Considering the following example:
function previewFile(file) {    var reader  = new FileReader();    reader.onloadend = function () {     console.log(reader.result);   }   reader.readAsDataURL(file); }   It states:
instanceOfFileReader.readAsDataURL(blob);
blob: The Blob or File from which to read.
How can a local file URL like: 'file:///C:/path-to/root.png' be passed to the readAsDataURL()   
Is FileReader() available in a Firefox Addon?
Right-click on the webpage and click “Inspect” in the menu. When the DevTools panel opens, click on the three vertical dots in the top-right corner and select “Undock into a separate window.” Press Ctrl + F on Windows or Cmd + F on Mac devices to find the blob URL. Enter “ blob:HTTP ” to find the link for the video.
The readAsDataURL method is used to read the contents of the specified Blob or File . When the read operation is finished, the readyState becomes DONE , and the loadend is triggered. At that time, the result attribute contains the data as a data: URL representing the file's data as a base64 encoded string.
In the sendAudioFile function create a new FormData object. Append the Blob to the the formData. Now send the formData with the POST method to your server and use the body property for the formData . const sendAudioFile = file => { const formData = new FormData(); formData.
To convert a URL to a Blob for FileReader.readAsDataURL() do this:
var request = new XMLHttpRequest(); request.open('GET', MY_URL, true); request.responseType = 'blob'; request.onload = function() {     var reader = new FileReader();     reader.readAsDataURL(request.response);     reader.onload =  function(e){         console.log('DataURL:', e.target.result);     }; }; request.send(); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With