nolanlawson / blob-util

Cross-browser utils for working with binary Blobs
https://nolanlawson.github.io/blob-util
Apache License 2.0
503 stars 45 forks source link

ReferenceError: btoa is not defined #53

Closed ChunAllen closed 6 years ago

ChunAllen commented 6 years ago

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?

nolanlawson commented 6 years ago

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