0

I have a requirement to parse the contents of a csv blob which has unicode characters. When I am trying to parse it using

Blob myBlob = EncodingUtil.base64Decode(response.getBody())

I am getting an exception saying -

"common.apex.runtime.impl.ExecutionException: Unrecognized base64 character: \u0003"

What would be the correct way to parse this blob ?

1
  • Is the response even encoded as base64? If it's not, you could simply .toString() the blob.
    – Derek F
    Commented Oct 14, 2021 at 11:35

1 Answer 1

0

The getBody method returns the CSV data as a UTF-8 string. No additional parsing necessary.

String csvString = response.getBody();

If you wanted a blob, use getBodyAsBlob.

Blob csvBlob = response.getBodyAsBlob();

Regardless, if your file has non-UTF-8 characters, you won't be able to read it as UTF-8. You'll need to check the data you're receiving to make sure it's in the proper format.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .