Base64 encoding, backslashes

(Miha) #1


when you encode in base64 and you need to send this encoded data in json format, how to solve this if you get backslashes in encoded string? i guess you need to somehow escape them?

I do this:


And then I do marshal and send data via http.client, but i get error from server. I guess the issue are backslashes.


(Norbert Melzer) #2

There should be no backslash in Base64 encoded data…

Base64 on Wikipedia says, that valid characters are 0-9, a-z, A-Z, +, and /.

Aside of that, as you can see on the playground, json.Marshal would escape the backslash for you.

(Miha) #3

hello, you are right, i was too quick! thank you for help!

i am having some strange issue with base64. If I send pdf or img files i get back from vendor server, 500, name too long.

But what is interesting is that if I send request (the same request) from Postman, than it works.

(Norbert Melzer) #4

Then the request is probably not the same…

(Miha) #5

I dump the request, copy/paste to postman and send:(

(Norbert Melzer) #6

Can you tell us how you do the request via go? Show some code?