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").
Add error message on the file preview
Show previous comments
(0)
Comments
(0)
Sign in to comment on this post
Answers approved by surveyjs Support
Hello Mohamed,
To prevent uploading forbidden files, you can send options.callback('error')
and add a CustomError
to the questions.errors collection.
JavaScriptimport { 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)
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.
ST
a year ago
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
JavaScriptsurvey.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