About EasyMorph Tutorials & Examples Web-help

Encoding a file with BASE64

What would be the proper/best way to encode a file content with BASE64 and post it using Web Request action. Is there any size limitation for Posting a data with Web Request? My concern is that some files might be pretty big couple of dozen MB.

Hi Bolud,

The best way depends on the file type and the target API.

EasyMorph has the encode() function which can be used to encode text to BASE64.

If you need to send a text file, you can:

  • import that file to EasyMorph with the “Import delimited text action” (separator should be set to “No separator” and “Treat numeric values” should be set to “Always as text”)
  • use the “Aggregate” action to concatenate all the lines
  • encode result to BASE64
  • use the “Iterate Web Request action” to send encoded text.

But there is no simple way to import the content of a binary file to EasyMorph.
So in case of a binary file, it’s better to use the “Run command” action with a thrid-party utility or the “PowerShell” action with a PowerShell script to convert that file.

And if the file should be sent as a multipart form data, you can you the “Web request” action to send it. In other case it’s better to use the “PowerShell” action to send the request.

In any case, a couple of dozens MB should not be a problem for the “Web request” action.

Hi @bolud
Could you please specify which web service are you going to use or place a link to the web service documentation?

I have some pdf files to upload using REST API was wondering f it was possible. The purpose is first POST data then upload corresponding PDF files using the REST response id’s.

Hello,

I’m also in a similar situation. I want to upload a ZIP file to Salesforce using the REST API. However, the file has to be uploaded in binary format.

Here is Salesforce API Documentation: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_insert_update_blob.htm?search_text=contentversion

And here’s a video tutorial on how to upload a file to Salesforce using the REST API, at 0:26 you will see the “VersionData” field in the API request, this is what I need to upload to Salesforce (which if I’m not wrong, is the base64 enconding of the binary data): How to Upload a Document in Salesforce Files Using Rest API | APPSeCONNECT - YouTube

@andrew.rybka At the moment, the situation would still be to run a Powershell script? Can you give me more information about how the Process with Powershell could work?

Thanks very much!

Roberto

Hello!

@andrew.rybka, I know it’s not so much EasyMorph related, but do you think you can give brief indications as of “where to start” to be able to do what you mention here:

So in case of a binary file, it’s better to use the “Run command” action with a thrid-party utility or the “PowerShell” action with a PowerShell script to convert that file.

I’m completely new to this, if you can tell me some utilities I could use or where to explore, that would be great :slight_smile:

Thanks,

Roberto

Hello Roberto,

Sorry for the delay with an answer - I had to discuss possible workarounds with a co-worker.

Now I have to test a PowerShell script. So I’ll get back to you later today.

Ok great, thanks very much for your help!

@roberto, here is an example project that imports specified file as a Base64-encoded string:
ImportFileAsBase64.morph (1.1 KB)

You can try to use that string in the “VersionData” field of a REST API request.

1 Like

Hello @andrew.rybka,

Perfect, this works like charm! :smiley:

When I encode a 10MB file I see EasyMorph Desktop slows down because of the size of the base64 code, that is something that can be fixed with more “RAM”, correct?

Finally, the first time I uploaded the file via “VersionData” through the API, I got an error, “Unable to read data from the transport connection: connection closed”. However, I tried it again after and it worked correctly. I also tried uploading a file double that size (20MB) and it also worked correctly. I haven’t been able to reproduce the error any more. Can this be caused by the API timing out, or could it be an EasyMorph issue?

Thanks again!

Roberto

Hello @roberto,

It seems that EasyMorph slows down only when you select the cell that contains a large text like a Base64 encoded file. Or when you open a preview that contains that large text, like the preview in the Web request action. It’s a UI issue and I don’t think that more RAM will help in such case. In any case, the execution time of the project should not be affected.

That error doesn’t look like an EasyMorph issue. Can you please post a screenshot of the error message if it will appear again?

Understood, thanks! If the error appears again, I’ll post it here.

Regards,

Roberto

To learn more about EasyMorph visit easymorph.com.