gwt-material-addins icon indicating copy to clipboard operation
gwt-material-addins copied to clipboard

MaterialFileUploader: Exception when uploading more than maxFiles

Open gerkster opened this issue 7 years ago • 1 comments

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

gerkster avatar Nov 07 '18 09:11 gerkster

Thanks will be looking into this, if you have time to submit a PR then it will be much appreciated.

kevzlou7979 avatar Nov 15 '18 01:11 kevzlou7979