Я разрабатываю приложение, используя gwt и использую gwtupload (версия 0.6.4) для загрузки файлов.Загрузка файлов работает во всех протестированных браузерах (Chrome, IE 9, FF 8/9).Однако при использовании Firefox, если размер загружаемого файла> 500 КБ, размер FF не будет выполнять публикацию формы.Если размер файла <500 КБ, FF публикует форму и файл загружается очень хорошо. </p>
У меня включена регистрация в сервлете, чтобы убедиться, что от Firefox не получено никаких сообщений, если файл не <500 КБ.</p>
Кто-нибудь знает, что это за проблема?Я проверил этот сайт, gwt / gwtupload, и также искал информацию на сайте Mozilla.
Спасибо.
Базовая настройка:
AttachmentDialog (aПодкласс GXT Dialog) содержит экземпляр настроенного экземпляра Uploader (gwtupload).При нажатии кнопки «Отправить» в AttachmentDialog выполняется вызов uploader.submit ().Загрузчик имеет обработчик onSubmit, прикрепленный к форме, который выполняет некоторые проверки и запрашивает сервлет загрузки о статусе.После возврата из проверки состояния загрузчик вызывает форму 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 );
}
Код загрузчика:
/**
* 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();
}
Когда sendAjaxRequestToValidateSession ()как указано выше, возвращается следующее:
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 );
}
}
};
Это работает для файлов всех размеров в Chrome и IE, но только для файлов <500 КБ в Firefox. </p>