Reputation: 31
I'm developing an application using gwt and using gwtupload (version 0.6.4) to perform file uploads. The file upload works in all browsers tested (Chrome, IE 9, FF 8/9). However, when using Firefox, if the file to be uploaded is > 500kb in size FF will not execute the Form post. If the file is < 500kb in size, FF posts the Form and the file uploads just fine.
I have logging turned on in the servlet to verify that no post is received from Firefox unless the file is < 500kb.
Does anyone have a clue as to what the issue might be? I've checked this site, gwt/gwtupload, and looked for information on the Mozilla site as well.
Thanks.
The basic setup is:
AttachmentDialog (a GXT Dialog subclass) contains an instance of a customized instance of Uploader (gwtupload). When the Submit button on the AttachmentDialog is clicked, the uploader.submit() call is made. The uploader has an onSubmit handler attached to the form that performs some checks and asks the upload servlet for status. Upon return from status check, the uploader calls the form.submit().
TestAttachmentDialog code:
private void initComponents() {
this.setHeading( "Attachment Upload Dialog" );
this.setModal( true );
//this.getHeader().setIcon( AbstractImagePrototype.create( Icons16Bundle.INSTANCE.attachment() ) );
this.getHeader().addStyleName( "defaultDialogHeader" );
this.setLayout( new FitLayout() );
final Uploader uploader = new Uploader( FileInputType.BROWSER_INPUT );
uploader.setFileInputSize( 35 );
HorizontalPanel hp1 = new HorizontalPanel();//for browsing file
hp1.setSpacing(5);
hp1.setHorizontalAlign( HorizontalAlignment.CENTER );
hp1.setStyleAttribute( "marginLeft", "auto" );
hp1.setStyleAttribute( "marginRight", "auto" );
hp1.add( new Hidden( "recordId", "5001" ) );
hp1.add( new Hidden( "dataTypeName", "aType" ) );
uploader.getForm().add( hp1 );
this.setButtons( Dialog.OKCANCEL );
this.getButtonById( Dialog.OK ).setText( "Submit" );
this.getButtonById( Dialog.OK ).addSelectionListener(
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected( ButtonEvent ce ) {
if (!("".equals( uploader.getFileName().trim() ))) {
uploader.submit();
ce.getButton().disable();
}
}
} );
this.getButtonById( Dialog.CANCEL ).addSelectionListener(
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected( ButtonEvent ce ) {
uploader.cancel();
}
} );
OnFinishUploaderHandler onFinishHandler = new OnFinishUploaderHandler() {
@Override
public void onFinish( IUploader uploader ) {
/*
* Current version of the SingleUploader calls the onFinish
* twice if the file was successfully uploaded. So this
* should prevent the double execution of the code.
*/
//if (!SimpleFileUploadDialog.this.onFinishCalled) {
if (uploader.getStatus() == Status.SUCCESS) {
UploadedInfo info = uploader.getServerInfo();
if ((info.message != null) && (!TestAttachmentUploadDialog.this.onFinishCalled)) {
TestAttachmentUploadDialog.this.setVisible( false );
if ("success".equalsIgnoreCase( info.message )) {
TestAttachmentUploadDialog.this.success = true;
MessageBox box = new MessageBox();
box.setTitle( "File Upload Complete" );
box.setMessage( "Attachment successfully uploaded." );
box.addCallback( successBoxCallback );
box.setButtons( MessageBox.OK );
box.setIcon( MessageBox.INFO );
box.getDialog().getHeader().addStyleName( "defaultDialogHeader" );
box.getDialog().setBodyStyleName( "defaultDialogBody" );
box.show();
}
else if (info.message.startsWith( "Special Upload Failure:" )) {
// notify user of special upload failure
}
else {
// notify user of other upload failure
}
TestAttachmentUploadDialog.this.onFinishCalled = true;
}
}
else if (uploader.getStatus() == Status.CANCELED) {
TestAttachmentUploadDialog.this.setVisible( false );
MessageBox box = new MessageBox();
box.setTitle( "File Upload Cancelled" );
box.setMessage( "Attachment upload has been cancelled." );
box.setButtons( MessageBox.OK );
box.setIcon( MessageBox.WARNING );
box.getDialog().getHeader().addStyleName( "defaultDialogHeader" );
box.getDialog().setBodyStyleName( "defaultDialogBody" );
box.show();
}
}
};
uploader.addOnFinishUploadHandler( onFinishHandler );
this.add( uploader );
this.setWidth( 450 );
this.setHeight( 150 );
}
Uploader code:
/**
* Handler called when the file form is submitted
*
* If any validation fails, the upload process is canceled.
*
* If the client hasn't got the session, it asks for a new one and the
* submit process is delayed until the client has got it
*/
private SubmitHandler onSubmitFormHandler = new SubmitHandler() {
public void onSubmit( SubmitEvent event ) {
if (!finished && uploading) {
uploading = false;
statusWidget.setStatus( IUploadStatus.Status.CANCELED );
return;
}
if (!autoSubmit && Uploader.fileQueue.size() > 0) {
statusWidget.setError( i18nStrs.uploaderActiveUpload() );
event.cancel();
return;
}
if (avoidRepeatedFiles && Uploader.fileDone.contains( getFileName() )) {
statusWidget.setStatus( IUploadStatus.Status.REPEATED );
successful = true;
event.cancel();
uploadFinished();
return;
}
if (!validateExtension( basename )) {
event.cancel();
return;
}
/*
* this is the code that gets called
*/
if (!hasSession) {
event.cancel();
try {
sendAjaxRequestToValidateSession(); // this is it
}
catch (Exception e) {
log( "Exception in validateSession", null );
}
return;
}
if (blobstore && !receivedBlobPath) {
event.cancel();
try {
sendAjaxRequestToGetBlobstorePath();
}
catch (Exception e) {
log( "Exception in getblobstorePath", null );
}
return;
}
receivedBlobPath = false;
addToQueue();
uploading = true;
finished = false;
serverResponse = null;
serverInfo = new UploadedInfo();
statusWidget.setVisible( true );
updateStatusTimer.squeduleStart();
statusWidget.setStatus( IUploadStatus.Status.INPROGRESS );
lastData = now();
}
};
public void submit() {
this.uploadForm.submit();
}
When sendAjaxRequestToValidateSession() noted above returns, the following is executed:
private final RequestCallback onSessionReceivedCallback = new RequestCallback() {
public void onError( Request request, Throwable exception ) {
String message = removeHtmlTags( exception.getMessage() );
cancelUpload( i18nStrs.uploaderServerUnavailable() + " (2) "
+ getServletPath() + "\n\n" + message );
}
public void onResponseReceived( Request request, Response response ) {
hasSession = true;
try {
String s = Utils.getXmlNodeValue(
XMLParser.parse( response.getText() ), "blobstore" );
blobstore = "true".equalsIgnoreCase( s );
// with blobstore status does not make sense
if (blobstore) {
updateStatusTimer.setInterval( 5000 );
}
uploadForm.submit(); // form submit is called but no post
}
catch (Exception e) {
String message = e.getMessage().contains( "error:" ) ? i18nStrs
.uploaderServerUnavailable()
+ " (3) "
+ getServletPath()
+ "\n\n"
+ i18nStrs.uploaderServerError()
+ "\nAction: "
+ getServletPath()
+ "\nException: "
+ e.getMessage()
+ response.getText() : i18nStrs.submitError();
cancelUpload( message );
}
}
};
This works for files of all sizes on Chrome and IE, but only for files < 500kb on Firefox.
Upvotes: 2
Views: 720