Custom Previews for File Upload Questions

Edit in →

SurveyJS File Upload questions support the file preview functionality out of the box (see the File Upload demo). This example demonstrates how you can override this functionality and implement custom file previews if required.

To implement custom file previews, follow the steps below:

  1. Disable built-in file previews.
    Set the File Upload question's showPreview property to false.

  2. Implement a custom file preview component.
    In this demo, a custom component adds a <div> element to the bottom of the question. When users select one or multiple files for upload, this <div> displays "Download file" and "Remove file" buttons per uploaded file.

  3. Register your custom component under the sv-file-preview name.
    In HTML/CSS/JavaScript projects, register the component in ReactElementFactory as shown in the index.js file.
    In React, register the component in ReactElementFactory as shown in the FilePreviewComponent.jsx file.
    In Angular, register the component in AngularComponentFactory as shown in the file-preview.component.ts file.
    In Vue 2, components are registered on creation. Make sure to specify "sv-file-preview" as the component name.
    In Vue 3 and Knockout, use techniques native to these libraries:

In this demo, files are uploaded to SurveyJS servers from where they are then deleted after a predefined period of time. We strongly encourage you to use your own servers for file uploads when you use SurveyJS to collect sensitive respondent data in your application.

Your cookie settings

We use cookies on our site to make your browsing experience more convenient and personal. In some cases, they are essential to making the site work properly. By clicking "Accept All", you consent to the use of all cookies in accordance with our Terms of Use & Privacy Statement. However, you may visit "Cookie settings" to provide a controlled consent.

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.