We use S3 server to store Salesforce files. Once it is uploaded there, if we need to download S3 files, we have to use AWS Signature Version 4 now onwards. We have another post (Use Named Credential to Upload File in S3) which will help in uploading files using AWS Signature Version 4. In this post will go for downloading file from AWS S3 server.
Below are steps for downloading S3 files
- Create named credential for AWS
- Create apex class to download file content
- Create LWC component to download on client side
- Call LWC component on record action
1. Create named credential for AWS
Follow steps mentioned in section Create a named credential for AWS Credential of from our other blog.
2. Create apex class to download file content
Once we created a named credential named S3Server from above steps. Let us create class which will download file content from AWS S3.
FileStore is object which hold S3 related information for files. It has S3 url, file extension and file name.
3. Create LWC component to download on client side
Create a LWC component which will get file data from apex and show that in different browser for saving/downloading it.
It will download file as soon as Download File action clicked on file store record.
4. Call LWC component on record action
Once LWC component is ready, create a action for LWC component on file store record object.

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

Related Posts:-
Use Named Credential to Upload File in S3
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