gwt-material-addins
gwt-material-addins copied to clipboard
MaterialFileUploader: Exception when uploading more than maxFiles
When you set
fileUploader.setMaxFiles(2);
and you have set up a maxFilesReachHandler:
fileUploader.addMaxFilesReachHandler(event -> {MessageUtils.showMessage("too many files");});
Then you try to upload 3 files, you will never see the message.
Reason: An exception is thrown in MaterialFileUploader.convertUploadFile()
Double.parseDouble(file.size)
as file.size is null for the file exceeding the maxfile limit, the parseDouble method fails.
Something like this is needed:
double fileSize = file.size != null ? Double.parseDouble(file.size) : 0;
There are even more bugs concerning the exceeding maxFiles. E.g.
uploader.on(FileUploaderEvents.COMPLETE, file -> {
String message = getResponseMessage(globalResponse);
CompleteEvent.fire(this, convertUploadFile(file),
new UploadResponse(file.xhr.status, file.xhr.statusText, message));
});
Here as well file.xhr is null for the 'maxFiles exceeding' file and therefore file.xhr.status will cause a NPE
Thanks will be looking into this, if you have time to submit a PR then it will be much appreciated.