I think it is best to add a custom exception from Receiver's receiveUpload:
Upload upload = new Upload(null, new Upload.Receiver() {
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
boolean typeSupported = ;
if (!typeSupported) {
throw new UnsupportedImageTypeException();
}
}
});
The exception is just the usual exception:
public class UnsupportedImageTypeException extends RuntimeException {
}
Then you just add a listener if the download fails, and check if your exception is the cause:
upload.addFailedListener(new Upload.FailedListener() {
@Override
public void uploadFailed(Upload.FailedEvent event) {
if (event.getReason() instanceof UnsupportedImageTypeException) {
} else {
LOGGER.error("Upload failed, source={}, component={}", event.getSource(), event.getComponent());
}
}
});
source
share