We are required to store a lot of business files in Salesforce Orgs. We can use Salesforce storage for storing these files but it becomes expensive for larger storage. Amazon S3 and Salesforce Integration can dramatically expand our CRM capabilities by delivering a scalable, secure, and efficient external storage option. This post will provide a step-by-step guide to downloading stored files from the S3 Server.
Check out our other post to upload files to the S3 Server.
Use Cases for Amazon S3 in Salesforce
Document and File Storage
Rather than using Salesforce’s more limited and pricey storage, store huge files and documents in S3. This is perfect for attaching PDFs, photos, movies, and other media items to your Salesforce entries.
Backup and Archiving
Use S3 to backup and archive Salesforce data. This provides data durability and accessibility while successfully controlling costs.
Data Lakes
For organisations that utilise Salesforce for customer data and big data analytics, S3 Server can be used to consume, store, and analyse massive amounts of structured and unstructured data.
Steps for downloading S3 files in Salesforce
- Create a named credential for AWS
- Create an apex class to download file content
- Create an LWC component to download on the client side
- Call LWC component on record action
1. Create a named credential for AWS
Follow the steps in the section Create a named credential for AWS Credential from our other blog Use Named Credential to Upload File in S3.
2. Create an apex class to download file content
Once we created a named credential named S3Server from the above steps. Let us create a class that will download file content from AWS S3.
FileStore is a Salesforce object that holds S3-related information for uploaded files. This object has fields for storing S3 URL, file extension and file name.
3. Create an LWC component to download on the client side
Create an LWC component that will get file data from Apex and show that in different browsers for saving/downloading it.
It will download the file when the Download File action is clicked on the file store record.
4. Call LWC component on record action
Once the LWC component is ready, create an action for the LWC component on the file store record object.
Add that action to the page layout. It will add a download file button on the record page.
Related Posts:-
Use Named Credential to Upload File in S3
View S3 File in Lightning Web Component
Authenticating Requests (AWS Signature Version 4)
Need Help?
Need some kind of help in implementing this feature, connect on my LinkedIn profile Dhanik Lal Sahni.
10 comments
Hello Dhanik.
I am able to download the files correctly without any problem.
But when I download files of bigger size let’s say 200mb.
Error says
System.CalloutException: IO Exception: Exceeded
max size limit of 6000000.
Please can you help me here how can we download with greater mb size
Hello Aman,
This is the default behavior for Salesforce. You can check this stack exchange post https://salesforce.stackexchange.com/questions/328492/api-file-download-maximum-file-size.
Thank You,
Dhanik
Hi Dhanik, I would like to access all files from a bucket , Is ther eany possiblity to get all the files instead of a perticular file using filename
Hello Rams,
I think you have to use CLI or PowerShell commands for downloading the complete bucket. You can refer this post https://stackoverflow.com/questions/8659382/downloading-an-entire-s3-bucket.
Thank You,
Dhanik
AccessDenied
Access DeniedRQ3W59SPRG0KBJVPbhrHVHbFMOg0n8mVkT48pq6qeCZWgaqlz3aO/DOnAKl2SRANROsfJ/zRYt9yAPO2P7UiwlsLpOE=got this error when i run this apex
Hello Abhiraj,
Please check the user access which you are using.
Thank You,
Dhanik
Hi Abhiraj,
I got below error. Please help me
NoSuchKey
The specified key does not exist.Test15RVFH77BBMSRD8MTE7naqX54rdYRbmnHrf0j9ovBWhwhRylXFUVL+rq57CB2GFFdPuLFWzvPEp9oAAjIfDANzaHR9qY=Thanks
Hello Suresh,
Where are you getting this error? Let us connect to discuss this issue.
Thank You,
Dhanik
hello dhanik
i am receving the correct response as a blob content , but its not downloading getting network failure error
Hello Vijay,
Please check link https://stackoverflow.com/questions/73791508/getting-failed-network-error-while-downloading-pdf-file-from-amazon-s3 for this issue.
Thank You,
Dhanik