Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaterialFileUploader: Exception when uploading more than maxFiles #375

Open
gerkster opened this issue Nov 7, 2018 · 1 comment
Open

Comments

@gerkster
Copy link

gerkster commented Nov 7, 2018

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

@kevzlou7979
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants