Convert attachment to base64 string

Hello,

Is there any way to convert the uploaded attachment and store it as a base 64 string for further use.

Thank you,

Rahul

Hello @rahul ,

You may use script node to convert the file into a base64 string and store it in context for future use. Do note that the file url is one time access.

Some examples are:

https://pqina.nl/blog/convert-a-file-to-a-base64-string-with-javascript/#encoding-the-file-as-a-base-string

https://www.codegrepper.com/code-examples/javascript/convert+file+into+base64+in+javascript

Hope this helps.

@rahul
Please remember that if you store the entire base64 converted image in the context, it will inflate the context size and it will slow down bot responses (the context passes =through all the backend services and NLP services).
I would suggest that if you have BotKit, you perform the Base64 translation there and save it locally or in a cache like redis. Avoid putting it into the context.

Hello @sameera.tumuluri ,

I have tried to use the code you suggested in the Script node, but the elements like “document”, “FileReader”, etc are all giving “Not defined errors” as shown below.

image

Could you please provide an example of the usage in Script node.

Thank you,

Rahul

@rahul
This is a server-side code and won’t work on botbuilder. You will need to use it on BotKit.
Also, this is just an example to show how it can be done. We may not be able to furnish you with a ready-made code.