Suggestion T15217
Visible to All Users

Add error message on the file preview

created a year ago

Hello,
I'm working on customizing the file preview using this sample : https://surveyjs.io/form-library/examples/custom-file-previews/reactjs
I want to know if it is possible to display an error message when the user try to upload a forbidden file. I tried to call this function but it doesn't work :
options.callback("error", "file extension forbidden").

Clipboard-File-1.png

Answers approved by surveyjs Support

created a year ago

Hello Mohamed,
To prevent uploading forbidden files, you can send options.callback('error') and add a CustomError to the questions.errors collection.

JavaScript
import { CustomError } from "survey-core"; survey.onUploadFiles.add((_, options) => { options.callback("error"); options.question.errors.push( new CustomError("You tried to upload a forbidden file") ); ... });

Please let me know if you have any further questions.

    Show previous comments (26)

      Ok thank you Jane.
      What about displaying multiline error ?

        Hello,

        I created a separate ticket on your behalf: T15476: File Upload - Display Multiline Errors. We placed it in our processing queue and will process it shortly.

          Hello,

          I've merged the https://github.com/surveyjs/survey-library/pull/7326 pull request. Now you can call the upload files callback with two arguments:
          first one - a list with successfully uploaded files
          second one - optional parameter with errors occurred during file upload

          JavaScript
          survey.onUploadFiles.add((survey, options) => { options.callback( options.files.map((file) => { return { file: file, content: file.name + "_url" }; }), ["custom error text"] ); });

          This functionality will be available in the nearest minor update next tuesday.

          Thanks, Serge
          SurveyJS Team