question

Giovanni Frigo avatar image
Giovanni Frigo asked

Cloudscript decode base64

Hey there,

I've tried looking both in the PlayFab docs and here in the forums, but I can't get to find an answer to a pretty simple problem: I'd need to decode a base64 encoded string into its utf-8 equivalent.

Tried with window.btoa, btoa, and the node.js-style Buffer. None of these things are available. How can I decode a base64 string?

This cannot be done on client side, it has to be done on CloudScript.

Thanks!

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

You may want to use the following code snippet to decode a base64 string into its utf-8 equivalent in CloudScript:

http://www.webtoolkit.info/javascript_base64.html#.XyocJKbiuUl

Then you can decode the base64 string simply by doing this:

Base64.decode("a_base64_string")
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Giovanni Frigo avatar image Giovanni Frigo commented ·

Ok, so still I'd have to include some specific code to be able to do that. Is there any reason why CloudScript does not support buffers? They could be useful in so many different cases..

Anyhow, for now I added the code found here, seems to do the job just fine https://github.com/jsdom/abab/blob/master/lib/atob.js

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Giovanni Frigo commented ·

CloudScript runs on V8 engine, "btoa" & "atob" are not part of the ECMAScript and therefore not implemented:

https://groups.google.com/forum/#!topic/v8-users/i6EJu-pmMts

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.