{..." I do this: audioReader = new FileReader(); audioFileStorage = e.target.files[0]; And when I do " /> {..." I do this: audioReader = new FileReader(); audioFileStorage = e.target.files[0]; And when I do " /> {..." I do this: audioReader = new FileReader(); audioFileStorage = e.target.files[0]; And when I do "/>

in Javascript: when uploading an audio file and using a FileReader why am I getting [object promise] instead of Data URL?

26 views Asked by At

on "inputAudioSE.addEventListener('change', (e)=>{..."

I do this:

audioReader = new FileReader(); audioFileStorage = e.target.files[0];

And when I do this:

function getAudioURL(){
  let URL = audioReader_SE.readAsDataURL(audioFileStorage);
  return URL;
}

audioReader_SE = getAudioURL();

function getAudioURLResult(){
  let URLresult =  audioReader.result;
  console.log(audioReader.result)
  return URLresult;
}

audioSrcStorage = getAudioURLResult();

And try to put the result into a file:

alert("Select the project folder to save encoded audio...");

let audioFileBlob = new Blob(
  [audioSrcStorage],
  {type: "text/plain"}
);

// create a download link for the blob
let audioObjectUrl = window.URL.createObjectURL(audioFileBlob);

// create an anchor tag for the actual download of the file
let audioFileAnchor = document.createElement("a");
audioFileAnchor.href = audioObjectUrl;

audioFileAnchor.download = "myEncodedAudio_Base64.txt";

audioFileAnchor.click();

//clean up
window.URL.revokeObjectURL(audioObjectUrl);

in the file I get [object promise] instead of the audioURL.

Any idea why? Thank you!

I tried the same thing with an image and it worked.

0

There are 0 answers