Custom Previews for File Upload Questions
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:
Disable built-in file previews.
Set the File Upload question'sshowPreview
property tofalse
.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.Register your custom component under the
sv-file-preview
name.
In HTML/CSS/JavaScript projects, register the component inReactElementFactory
as shown in theindex.js
file.
In React, register the component inReactElementFactory
as shown in theFilePreviewComponent.jsx
file.
In Angular, register the component inAngularComponentFactory
as shown in thefile-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.