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'sshowPreviewproperty 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-previewname.
In HTML/CSS/JavaScript projects, register the component inReactElementFactoryas shown in theindex.jsfile.
In React, register the component inReactElementFactoryas shown in theFilePreviewComponent.jsxfile.
In Angular, register the component inAngularComponentFactoryas shown in thefile-preview.component.tsfile.
In Vue.js, register the component inComponentFactoryas shown in themain.tsfile.
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.