Newer Version Available
Understand File Uploads in Salesforce
For the purposes of thinking about uploading files from an LWC, we can simplify the representation to four related objects.
An uploaded, attached, or generated file is represented primarily by the ContentDocument object. However, this object holds no file data. Instead, versions of an uploaded file are stored as ContentVersion objects. With this structure, you can update a file by uploading a new version. Each upload creates another ContentVersion record, and this record is where the binary file data for the upload is stored.
That record represents the file. To associate an uploaded file to another record—for example, to attach photos of a vehicle to a car rental agreement record—the ContentDocumentLink object is used to link the two records together. A ContentDocumentLink object represents the relationship between a ContentDocument and any other record. Associate an uploaded file with any number of other records by creating the appropriate ContentDocumentLink records that join them.
When online, the LWC code for creating a file upload, while non-trivial, is straightforward, using standard Lightning Data Service (LDS) adapters like createRecord.
Supporting offline uploads from mobile clients is more challenging. Not only is it hard to manage the various relationships between records, but there’s also the challenge of holding binary file data in an offline store for later upload. To manage these technical issues, use the dedicated, mobile-specific file upload adapter: createContentDocumentAndVersion.
Supported file sizes for uploads are dependent on device memory, and large file sizes can cause compatibility issues. Keeping file upload sizes (especially images) under 100 MB maximizes compatibility.
Any supported file type can be uploaded, however only draft images can be viewed in the context of an LWC.