gwtupload
gwtupload copied to clipboard
Make server error constants be available on the GWT client
I created a BaseUploadStatus
that overrides the default (Window.alert()
) behavior.
public class CustomUploadStatus extends BaseUploadStatus {
public interface FileTooLargeHandler {
void onFileTooLarge();
}
private final FileTooLargeHandler fileTooLargeHandler;
public CustomUploadStatus(
FileTooLargeHandler fileTooLargeHandler) {
this.fileTooLargeHandler = fileTooLargeHandler;
}
@Override
public void setError(String msg) {
setStatus(Status.ERROR);
if (msg.startsWith("The request was rejected because its size:")) {
fileTooLargeHandler.onFileTooLarge();
}
}
}
I would like to avoid the msg.startsWith("The request was rejected because its size:")
. Depending on that particular string couples me too much with the contents of UploadServlet.properties
.
size_limit=The request was rejected because its size: {0} KB, exceeds the maximum: {1} KB
It seems that the UploadServlet.properties
file is only available on the server. It would be nice if those messages could be available to a GWT app (maybe leveraging GWT's Messages)
Or, maybe I could use a specific Status
for when the uploaded file is too large?