Problems with base64 decoding

Hi all! I am desperate.

I am using the instructions I have read in this forum to translate a pdf file into a base64 string, and also to decode a base64 string back into a pdf. When I try this round way with one specific pdf it works well. I am able to translate the pdf file into a string and translate the string into the specific pdf file. I can see the process has work well because I am able to open the final file and check it is the one I used in first case.

However, I have a problem when I send this b64 string to an application where I want to upload this pdf file. It happens to occur that when I try to download the file from the application, I cannot open the pdf file because I receive an error message “We cannot open this file. An error has occurred”.

I send this base64 string to the application through an Application’s API.

I have also done the operation uploading the file directly in the application (loging in the app) and in this case, when I download the file (the same one I used with the decoding and the API process I told you previously), it is perfect and I can open it with no problem.

It seems as if the decoding invoke we usually use in UiPath Studio, was not performing the same operations as the one being used by the application, and so, the final result of the application for my base64 string is not correct.

Have you ever suffered this kind of problem? Any clue on how to solve it? I am really desperate and I cannot get any support from the web application creators.

Thank you very much for your help!!!


Another piece of information. This application also comunicates with a third party application and exchanges files with it in base64 protocol. These files received by the application I can download and open them with no problem. My problem comes only with these files I transform into b64 and I do upload to the application using its API (the POST operation resulting in a code 200 success).

Here’s an example of how to encode a string to Base64 in UiPath Studio:

1. Create a new sequence in UiPath Studio.
2. Drag and drop a "Message Box" activity onto the design surface.
3. In the "Message Box" activity, enter the following code in the "Text" field:

Convert.ToBase64String(Encoding.UTF8.GetBytes("Your string here"))

4. Replace "Your string here" with the string you want to encode.
5. Click the "OK" button to save the message box activity.
6. Run the workflow and you will see a message box with the Base64 encoded string of your input string.

Here’s an explanation of the code used above:

• Encoding.UTF8.GetBytes("Your string here") converts the input string to a byte array using UTF-8 encoding.
• Convert.ToBase64String() method converts the byte array to a Base64 encoded string.

You can use this code in your UiPath workflows to encode any string to Base64.

For the pdf creation, if you are using Microsoft Print to PDF to save it, you may have the behavior that you are describing as it will not be recognized as a valid PDF file by other tools.

Try to create it in Adobe Acrobat Reader or other express tools.

1 Like

Thank you very much Marian for your quick answer. In fact. I am dealing with converting files into b64 strings and b64 strings into files. Not string into b64.

Anyway, the point of the Microsoft converter might be helpful. Maybe, this is what the creators of the application are using to transform my base64 string into a pdf and that is why I cannot opened their result pdf file. I will try to check.

Also, if someone else has suffered this problem of a theoretically perfectly valid base64 string of a pdf file that translates into a “non-readable” pdf file after uploading it to a business web application, and has come to a solution, please give some information on how did you proceed.

Thank you very much,

Thank you to all that read my question. At the end it resulted that I had a bug in my programming that would change all characters to lower case before calling the API. That is why it did not work properly the b64 decoder. I am sorry for all disturbances I may have caused to you.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.