nolanlawson/blob-util

ReferenceError: btoa is not defined

ChunAllen opened this issue · 1 comments

I'm passing the audio blob file using JavaScript XMLHttpRequest();
here's the my current code where the audio is the blob type audio/wav

  var xhr = new XMLHttpRequest();
  xhr.open('POST', "/", true);
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xhr.send(audio);

then on my Express JS node, I'm receiving the params using req.body

blobUtil.blobToBase64String(req.body).then(function (base64String) {
   console.log('success')
 }).catch(function (err) {
   console.log('error')
 });

but I'm getting an error which is ReferenceError: btoa is not defined

Did I missed something here?

This is a library for browsers, and it appears you're using it in Node.js where btoa is unavailable. I suggest looking into Buffers instead: https://nodejs.org/api/buffer.html