2

I have .wav file, placed on "http://yy.zz/1.wav". How can i fetch it with base64 encoding on client-side javascript?

getFile('http://yy.zz/1.wav', (file) => {
  console.log(getBase64File(file)); // profit
});

1 Answer 1

1

If the file is on the same domain or you have CORS enabled on the external site, you can do the following:

$.get("http://localhost/content/sound/hello.wav", function(file){
   let fileInBase64Format = btoa(unescape(encodeURIComponent(file)));
   console.log(fileInBase64Format);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.