Appiphony
 
  • Products
    • Merge Connect Document Generation
    • eSign Connect Docusign Integration
    • Parse Connect Document Parsing
    • Share Connect SharePoint Integration
    • Drive Connect Google Drive Integration
    • Experience Connect Experience Cloud Add-on
  • Company
  • Resources
    • Documentation Learn about our products
    • Blog Salesforce guides and tutorials
    • Customer Stories How our customers succeed
    • Videos Visit our YouTube channel
    • Company Get to know Appiphony
    • Careers View openings
    • PDO Services Build with Appiphony
    • PDO Customer Portal Access our customer portal
  • Pricing
Product Documentation Contact Us

Adding the File Uploader Event Listener Code Snippet to Your Form

In order to use the File Uploader component, the File Uploader event listener code snippets need to be added to an event trigger. 

  1. Open up your event trigger’s javascript file (.js) in your desired source code editor. In this example we will be using a case creation form as the event trigger.
  2. First, if you want toasts too appear you will want to add import Toast from ‘lightning/toast’. This will be added with the other imports.
    Code:

    import Toast from ‘lightning/toast’
  3. Next, we will add a few more variables for tracking and the uploader:
    • @track uploadedFile = false - Checks to see if user has uploaded at least one file, used in conjunction with disableCreateButton().
    • uploaderListener = null - Variable to be used as a reference for Callback methods added later.
    • expectedOrigin = window.location.origin - Variable for postMessage() security via storing of the current site origin.
    • @track startTime = null - Checks the start time of file upload, which will be referenced later.
    • @track endTime = null - Checks the end time of file upload, which will be referenced later.
    • @track done = false - Checks the completion of file upload, which will be referenced later.
      Code:

      @track uploadedFile = false
      uploaderListener = null
      expectedOrigin = window.location.origin
      @track startTime = null
      @track endTime = null
      @track done = false
  4. Next, we will add @track files = [] which is an array that will be used to store the uploaded files.
    Code:

    @track files = []
  5. We will now add the elapsedTime() method that will use the start and end time variables mentioned earlier to calculate the duration between the two.
    Code: 

    get elapsedTime() {
    if (this.startTime && this.endTime) {
    const duration = this.endTime - this.startTime;
    const durationMinutes = Math.floor(duration / 60000);
    const durationSeconds = Math.floor((duration % 60000) / 1000);
    const durationMilliseconds = Math.floor((duration % 1000) / 100);
    return `${durationMinutes}m ${durationSeconds}s ${durationMilliseconds}ms`;
    }
    return '';
    }
  6. Under the handlecreate() method we will add a postmessage method that lets the File Uploader component know when a case has been created and to provide it the recordId.
    Code:

    this.startTime = new Date();
    window.postMessage({ type: 'expconnect:upload', recordId: caseId }, this.expectedOrigin);
  7. We will now add two Callback methods at the very end of our event trigger’s javascript file:
    • connectedCallback() - Allows for fetching of data and adding event listeners.
    • disconnectedCallback() - Allows for cleaning up of data and removal of event listeners.
      Code:

      connectedCallback() {
      this.uploaderListener = this.handleUploaderEvent.bind(this);
      window.addEventListener('message', this.uploaderListener);
      }

      disconnectedCallback() {
      window.removeEventListener('message', this.uploaderListener);
      }
  8. Finally, we will add the handleUploaderEvent(event) method after the Callback methods. This method will allow you to set an array of accepted events from the file uploader component. With desired logic, you can customize your File Uploader experience. For more information on listening for uploader events and accepted events visit the File Uploader Events article. 
    Code:

    handleUploaderEvent(event) {
    // Handle the custom event from the uploader

    if (event.origin !== this.expectedOrigin) {
    console.warn(`Unexpected event origin: ${event.origin}`);
    return;
    }

    console.log(JSON.stringify(event.data, null, 2));
    const acceptedEvents = [
    'expconnect:initialized',
    'expconnect:uploadresult',
    'expconnect:fileschange',
    'expconnect:uploadprogress'
    ];

    if (!acceptedEvents.includes(event.data.type)) {
    console.log('Form discarding event: ' + event.data.type);
    return;
    }

    if (event.data.type === 'expconnect:uploadresult' && event.data.isSuccess) {
    Toast.show(
    {
    label: 'Success!',
    message: 'Your case has been created successfully and all files have been uploaded.',
    variant: 'success',
    mode: 'pester'
    },
    this
    );
    this.endTime = new Date();
    this.done = true;
    this.loading = false;
    this.uploadedFile = false;
    } else if (event.data.type === 'expconnect:uploadresult' && !event.data.isSuccess) {
    Toast.show(
    {
    label: 'Error!',
    message: `There was an error creating your case or uploading files: ${event.data.error}`,
    variant: 'error',
    mode: 'pester'
    },
    this
    );
    this.endTime = new Date();
    this.loading = false;
    } else if (event.data.type === 'expconnect:fileschange') {
    this.files = event.data.files.map((f) => ({
    name: f.name,
    size: f.size,
    progress: 0
    }));
    this.uploadedFile = event.data.files && event.data.files.length > 0;
    } else if (event.data.type === 'expconnect:uploadprogress') {
    const {
    file: { name },
    progress
    } = event.data;
    const file = this.files.find((f) => f.name === name);
    if (file) {
    file.progress = progress;
    }
    }
    }

Getting Started

  • Introduction
  • Installation & Setup
    • Assigning License & Permissions
    • Assigning Automation Users
    • Assigning Permission Sets to Experience Site
    • Adding the Files Component
    • Files Component Configurations
    • Adding the File Uploader Compoment
    • File Uploader Component Configurations
    • Adding the File Uploader Event Listener Code Snippet to Your Form
    • File Uploader Events
  • FAQs
    • How do I update Experience Connect?
    • How is Experience Connect used in a sandbox environment?
    • How do I open a support ticket with the Experience Connect team?
    • What are the Experience Connect remote sites?
    • What's the difference between the Files Component and the File Uploader Component?
  • Release Notes

Features

  • Files Component
  • File Uploader Component

Integrations

  • Drive Connect
    • Drive Links Component
    • Automate Drive
  • Share Connect
    • SharePoint Links Component
    • Automate SharePoint

Billing

  • Purchase
  • Manage
    • Users
    • Terms
    • Payment Info
    • Cancellation

Products

  • eSign Connect
  • Parse Connect
  • Share Connect
  • Merge Connect
  • Drive Connect
  • Experience Connect

Pricing

  • Drive Connect Pricing
  • eSign Connect Pricing
  • Share Connect Pricing
  • Merge Connect Pricing
  • Parse Connect Pricing
  • Experience Connect Pricing

Resources

  • Documentation
  • Blog
  • Customer Stories
  • Videos
  • Company
  • Careers
  • PDO Services
  • PDO Customer Portal

© 2026 Appiphony, LLC. All rights reserved.

Various trademarks held by their respective owners.

Manage Cookies • Policy & Terms
Loading Comments...