上传文件时,Firefox无法发布表单> 500kb使用gwtupload

时间:2012-03-26 15:41:43

标签: firefox file-upload gwtupload

我正在使用gwt开发一个应用程序并使用gwtupload(版本0.6.4)来执行文件上传。文件上传适用于所有测试的浏览器(Chrome,IE 9,FF 8/9)。但是,在使用Firefox时,如果要上传的文件是>厚度为500kb的FF将不会执行表格帖子。如果文件是<大小为500kb,FF发布表格,文件上传就好了。

我在servlet中打开了日志,以验证没有从Firefox收到任何帖子,除非该文件是< 500KB。

有没有人知道问题可能是什么?我已经检查了这个网站gwt / gwtupload,并在Mozilla网站上查找了相关信息。

感谢。

基本设置是:

AttachmentDialog(GXT Dialog子类)包含Uploader(gwtupload)的自定义实例的实例。单击AttachmentDialog上的Submit按钮时,将调用uploader.submit()。上传器有一个onSubmit处理程序附加到表单,执行一些检查并询问上传servlet的状态。从状态检查返回后,上传者调用form.submit()。

TestAttachmentDialog代码:

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上的所有尺寸的文件,但仅适用于文件&lt; Firefox上500kb。

0 个答案:

没有答案