Skip to main content

Important: the technique described in this post was always a work-around for missing functionality. That functionality is now available in your mobile apps. See:

 

Upload Images While Offline

 

Do NOT use the techniques described in the below article. Replace any existing implementations with the supported technique described in the official documentation linked above.

 

Upload Photos from LWCs Using `lightning-input` Base Component

 

As demonstrated last month, and discussed at this months' office hours, here is the sample code and documentation for a technique for uploading images from a Lightning web component running in the Field Service Mobile app. This technique uses the `lightning-input` component, and illustrates the use of LWC, LDS, an Apex trigger, and standard JavaScript to select, resize, and upload photos, and attach them to business records such as a Work Order.

 

There are lots of details of the technical limitations in the attached PDF. For now, a quick reminder:

 

  • This technique isn't supported by Salesforce, now or ever. Do not use in Production.
    • Use the officially supported technique linked to above instead. 
  • Using this at scale is untested and will surely cause problems.
  • Only works on iOS in Summer ’22.
  • Suggested for online use only, though for POC testing purposes only, it should work while offline.

We hope this is useful as people build LWC-based features, allowing you to move past limitations in this area, at least for your development phase. 

14 comments
  1. Jun 14, 2024, 4:11 PM

    @Michael Alderete  Hello Michael, sorry to bother here in an old thread, but my question is related to the "CreateContentDocumentAndVersion". We had to write our own LWC to upload files because our client need to add custom information against each selected files.  I am using lightning-input type="file" , createContentDocumentAndVersion and createContentDocumentLink to achieve this. It works perfectly fine on iPhones, but on Android, we randomly get an error (notreadablerror : the requested file could not be read typically due to permission problems) typically when the user mix "Take a photo" and "Choose from Library" while choosing the pictures. 

     

    My question is: is there a limitation on android to achieve this? That error doesn't seem to occur when doing the same tests using the OOTB file upload feature. What am I missing?

     

    I have posted a question about this here: https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007epbukSAA

0/9000