Home SalesforceApex Download S3 File in Salesforce using AWS Signature Version 4.0

Download S3 File in Salesforce using AWS Signature Version 4.0

by Dhanik Lal Sahni
Download S3 Files

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

  1. Create a named credential for AWS
  2. Create an apex class to download file content
  3. Create an LWC component to download on the client side
  4. 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.

Record Action for Salesforce Record

Add that action to the page layout. It will add a download file button on the record page.

Add Record Action on Page Layout

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.

You may also like


Aman Patil December 18, 2021 - 11:49 pm

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

Dhanik Lal Sahni December 29, 2021 - 10:18 am

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,

Rams September 13, 2022 - 5:05 pm

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

Dhanik Lal Sahni September 14, 2022 - 7:07 pm

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,

Abhiraj P R April 4, 2023 - 9:56 pm

AccessDeniedAccess DeniedRQ3W59SPRG0KBJVPbhrHVHbFMOg0n8mVkT48pq6qeCZWgaqlz3aO/DOnAKl2SRANROsfJ/zRYt9yAPO2P7UiwlsLpOE=

got this error when i run this apex

Dhanik Lal Sahni April 13, 2023 - 6:39 pm

Hello Abhiraj,

Please check the user access which you are using.

Thank You,

Suresh June 1, 2023 - 10:20 pm

Hi Abhiraj,
I got below error. Please help me

NoSuchKeyThe specified key does not exist.Test15RVFH77BBMSRD8MTE7naqX54rdYRbmnHrf0j9ovBWhwhRylXFUVL+rq57CB2GFFdPuLFWzvPEp9oAAjIfDANzaHR9qY=


Dhanik Lal Sahni June 8, 2023 - 8:07 pm

Hello Suresh,
Where are you getting this error? Let us connect to discuss this issue.

Thank You,

Vijaya Kumar Vegi June 18, 2023 - 5:46 pm

hello dhanik
i am receving the correct response as a blob content , but its not downloading getting network failure error


Leave a Comment