Retrieve Uploaded Files for Preview Using File Names

Edit in →

When respondents attach a file to a survey, this file can be uploaded to a server or stored directly within a JSON object with survey results. The File Upload demo describes both approaches and shows how to upload a file and store only its URL in survey results. However, if you store file identifiers different from URLs (for instance, file names), file previews are unavailable. This demo explains how to enable file previews when survey results store only file names. Read more...

Themes
Color palette
Question appearance
Sorry, we can't retrieve the data from server. Please comeback later.

When respondents attach a file to a survey, this file can be uploaded to a server or stored directly within a JSON object with survey results. The File Upload demo describes both approaches and shows how to upload a file and store only its URL in survey results. However, if you store file identifiers different from URLs (for instance, file names), file previews are unavailable. This demo explains how to enable file previews when survey results store only file names.

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.

Upload Files to a Server

The steps to upload a file to a server are the same as for the File Upload demo, except that you should save file names instead of URLs on step 2:

  1. Disable the storeDataAsText property for the File Upload question.
  2. Use SurveyModel's onUploadFiles event to upload files and save file names in survey results.
  3. Enable the File Upload question's waitForUpload property to ensure that users won't complete the survey until files are uploaded.

Enable File Previews

When survey results store file names, a File Upload question cannot retrieve the files to display their previews. To enable the previews in this case, implement SurveyModel's onDownloadFile event handler. Within this handler, you need to fetch the required file from the server, encode it to a Base64 string, and pass this string as the second argument to the options.callback method. This demo uses the FileReader API to encode files.

Why we use cookies.

This site uses cookies to make your browsing experience more convenient and personal. Cookies store useful information on your computer to help us improve the efficiency and relevance of our site for you. In some cases, they are essential to making the site work properly. By accessing this site, you consent to the use of cookies.

For more information, refer to DevSoft Baltic’ Terms of Use & Privacy Statement.

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.