Upload Files to Amazon S3

This section explains how to create a custom Lightning Web Component (LWC) that uploads the files directly from Salesforce to an Amazon S3 bucket.

Prerequisites 

Set up an external data source for Amazon S3 bucket in Salesforce org. SeeS3 External Data Source Setup Guide.

Overview 

The Bring Your Own Blob (BYOB) architecture offloads the storage and processing of files from Salesforce servers to Amazon S3 servers. By using a client-side LWC approach, files are uploaded directly from the browser to Amazon S3.

How It Works 

The upload process includes three primary stages:

  • Initialize Upload: Retrieve Amazon S3 upload parameters and signed URLs from Salesforce.

  • File Upload Process: Transfer the file content directly from the browser to Amazon S3.

  • Complete Upload: Notify Salesforce to create a ContentDocument record that links to the S3 file.

  • Initialize the Upload

    When a user selects a file, the LWC first retrieves the S3 upload parameters using the Salesforce Connect API.

  • Upload File Content to Amazon S3

    Use the code snippet below to create an LWC component to upload the file and add it to a Lightning page.

  • Complete the Upload

    Once all content is transferred to S3, the LWC invokes the complete upload API in Salesforce.

  • Error Handling and Best Practices

    If a user cancels the upload or an error occurs during the process, the LWC should call the abort file upload API to clean up any partially uploaded data in S3.