To base64 string from file upload, multipart, stream

Continuing the discussion from portal.getMultipartText() returns null:

Enonic version: 6.6.2-SNAPSHOT
OS: Mac

I would like Enonic to provide a library function, which returns a base64 “pure” js string.

Perhaps a generic io.streamToBase64(stream)

And perhaps a convenience portal.getMultipartAsBase64(name, index) which is simply io.streamToBase64(portal.getMultipartStream(name, index)) behind the scenes.

Does atob / btoa work for your usecase?

Nope, ASFAIK. atob, btoa lives in the window object in the browser and only works with text, not binary data…

I’m talking serverside, on an Enonic stream object, which I’m guessing in reality is sorta Java, not Javascript.

Btw this is currently a BLOCKER for us.

I guess I’ll have to start looking for Java code for this… dunno whether that will lead to success.

I started making a simple lib for converting between stream and base64. Hope to be done soon and put it in github.
This will be a separate lib outside of XP.

4 Likes

@ComLock can you check this XP lib and see if it solves your problem?

2 Likes

Yes that worked beautifully :slight_smile: thanks

I think I made base64 encoding in the lib-util but it probably didn’t get merged yet.