-1

I have looked through many questions and do not see one which worked. I am working with UCWA API responses where it is returning the following for incoming messages:

data:text/plain;charset=utf-8,hi+maya

The objective is to capture the input text "hi maya". I have tried doing a split on the string to capture everything after the comma and I have also tried decodeURIComponent(msg.msgIn). I have also looked at buffer for nodejs. Neither one is working, so would appreciate help on how to parse this.

Also, I have looked at similar posts here and it is related to downloading a file. I don't want to have to download a file - just directly take the string from the api response.

Thanks.

AA Shakil
  • 538
  • 4
  • 14
Heather
  • 133
  • 4
  • 15

1 Answers1

0

decodeURIComponent doesn't "decode" +es into spaces. Go figure. The solution is to do that yourself first:

function decodeDataUri(uri) {
  const data = uri.slice(uri.indexOf(',') + 1);
  return decodeURIComponent(data.replace(/\+/g, ' '));
}

console.log(decodeDataUri('data:text/plain;charset=utf-8,hi+maya'));
Jordan Running
  • 102,619
  • 17
  • 182
  • 182