I want to convert a PDF file into its Base64 version. Everything I1ve found in my internet research involves promisses, async functions and DOM manipulation, which is not supported by Studio Pro (as far as I know). Usually you need to create an HTML page with an input of type file and an id. Then you use getElementById() to get the file, create an async function that converts the file into Base64.
But I’m working with local files and I need to convert them without uploading them anywhere. I’ve tried using btoa() but Studio Pro throws and error sayong Variable 'btoa' is not defined, which is weird because it’s not supposed to be a variable.
Apparently, it has to be run using PowerShell. I want it to run in the background, so I tried running the command in the prompt by typing PowerShell, then ENTER, then trying the command above again. It works just fine when I run it manually, but not when I use the Command Prompt activity.
Thank you. Your suggestion works, but I’ve just realized that it’s not what I need.
The file cannot be decoded back into a PDF file, probably because I’m using the Read Text activity. So it encodes the text into base64. What I actually need is to encode the PDF file into base64.
You can set up 2 variables called pdfPath (path of the file you want to convert to base64) and outputPath (file where the resulting base64 code will be saved), and then use the following command inside the Command Prompt activity (with “Calculate a value” selected):
Hey! If you’re still getting stuck with the built-in activities, I usually find that a quick ‘Execute JavaScript’ block is the most reliable way to handle this in ElectroNeek. It keeps the workflow clean and avoids any weird data type issues.
When I’m setting these up, I often use a web-based converter (like this- Image to Base64 Converter - Encode Images Instantly Online) just to generate a ‘known good’ string for comparison. It’s a lifesaver for checking if the issue is with the file path logic or the actual encoding block in your bot.
Are you trying to pass the string into an API call, or just saving it to a variable for now? Might be able to help with the JS snippet if you need it!