cancel
Showing results for 
Search instead for 
Did you mean: 

Download file from Salesforce using API

MetVonghiran
Level 4

Hello,

I would like some advice regarding how to download a file from Salesforce to local folder.

I'm using the BP Skill "Salesforce" to obtain the ContentDocumentId. 

I use the following "GET" API to retrieve the base-64 from Salesforce

/services/data/v47.0/sobjects/ContentVersion/[Id]/VersionData

I'm stuck with how to convert the response content to a physical file.

I figure I have to use the code stage to convert the data, but I'm not quite sure how to achieve it.
Any help would be highly appreciated.

Best Regards

Met Vonghiran



------------------------------
Met Vonghiran
Consultant
Deloitte
Asia/Tokyo
------------------------------
3 REPLIES 3

ashish.easow
Staff
Staff
hello Met,

sample google search - https://bytes.com/topic/visual-basic-net/answers/362824-convert-base64-string-file

------------------------------
Ashish Easow
Senior Consultant - Professional Services
Blueprism
Asia/Kolkata
------------------------------

IshanMahajan
Level 7
Dim binaryData() as byte = convert.FromBase64String(Base64Str)
Dim fs as new fileStream (Filepath, FileMode.CreateNew)

fs.Write(binaryData,0,binarydata.Length)

fs.close

Use this code, Base64Str is your base 64 String, filepath should be entire file path where you want to save file, like c:/temp.pdf or d:/new.txt , i hope you know the extention.
You can put this in a code stage and run it, it works fine. you will have to import Microsoft.VisualBasic name space in object.

------------------------------
Ishan Mahajan
India
------------------------------

Thank you Ashish and Ishan

I tried the code and it was able to create a file. This is really a big progress.

However, I just realize that the result that I got from using REST API was not in base64 format (it was a raw binary).
Based on the discussion in the link below, I have to create a SOAP API request. If I'm able to achieve that then I could combine with the code stage that you provide to get a physical file.
https://stackoverflow.com/questions/60283198/get-base64-data-of-file-from-salesforce

I'm still new to the concept of API and how to use BluePrism to call it.
I will try to use Utility-HTTP to see if I could get the base64 out of Salesforce or not.

Thank you so much  



------------------------------
Met Vonghiran
Consultant
Deloitte
Asia/Tokyo
------------------------------