1

我想通过“GWT Upload”( https://code.google.com/p/gwtupload/)向 Google App Engine 提供文件上传。在上传过程中出现错误。作为UploadActionservlet,我使用内置:gwtupload.server.gae.AppEngineUploadAction

servlet 在 web.xml 中配置如下:

<context-param>
    <!-- max size of the upload request -->
    <param-name>maxSize</param-name>
    <param-value>3145728</param-value>
</context-param>
<context-param>
    <!-- Useful in development mode to slow down the uploads in fast networks. 
        Put the number of milliseconds to sleep in each block received in the server. 
        false or 0, means don't use slow uploads -->
    <param-name>slowUploads</param-name>
    <param-value>200</param-value>
</context-param>

<servlet>
    <servlet-name>uploadServlet</servlet-name>
    <!-- This is the default servlet, it puts files in session -->
    <servlet-class>gwtupload.server.gae.AppEngineUploadAction</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>uploadServlet</servlet-name>
    <url-pattern>*.gupld</url-pattern>
</servlet-mapping>

在上传过程中,进度条会按百分比前进,然后显示以下错误:

错误信息

但是日志中没有更多详细信息。

错误消息显示gwtupload.server.gae.MemCacheFileItemFactory$CacheableFileItem带有方法的类setHeader()。这很奇怪,因为我在那个类中找不到方法。这里发生了什么事?

编辑: 这基本上是我使用的所有自定义代码。在服务器端,我使用gwtupload.server.gae.AppEngineUploadActionservlet 中的构建。

package com.uploadtest.client;

import gwtupload.client.IUploadStatus.Status;
import gwtupload.client.IUploader;
import gwtupload.client.IUploader.UploadedInfo;
import gwtupload.client.MultiUploader;
import gwtupload.client.PreloadedImage;
import gwtupload.client.PreloadedImage.OnLoadPreloadedImageHandler;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GWTUploadTest2 implements EntryPoint {


    // A panel where the thumbnails of uploaded images will be shown
    private FlowPanel panelImages = new FlowPanel();

    public void onModuleLoad() {
        // Attach the image viewer to the document
        RootPanel.get("thumbnails").add(panelImages);

        // Create a new uploader panel and attach it to the document
        MultiUploader defaultUploader = new MultiUploader();
        RootPanel.get("default").add(defaultUploader);

        // Add a finish handler which will load the image once the upload finishes
        defaultUploader.addOnFinishUploadHandler(onFinishUploaderHandler);
    }

    // Load the image in the document and in the case of success attach it to the viewer
    private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
        public void onFinish(IUploader uploader) {
            if (uploader.getStatus() == Status.SUCCESS) {

                new PreloadedImage(uploader.fileUrl(), showImage);

                // The server sends useful information to the client by default
                UploadedInfo info = uploader.getServerInfo();
                System.out.println("File name " + info.name);
                System.out.println("File content-type " + info.ctype);
                System.out.println("File size " + info.size);

                // You can send any customized message and parse it 
                System.out.println("Server message " + info.message);
            }
        }
    };

    // Attach an image to the pictures viewer
    private OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() {
        public void onLoad(PreloadedImage image) {
            image.setWidth("75px");
            panelImages.add(image);
        }
    };

}

除此之外,我在我的包层路径中添加了以下罐子:

  • log4j-1.2.17.jar
  • gwtupload-gae-0.6.6.jar
  • gwtupload-0.6.6.jar
  • commons-fileupload-1.3.jar
  • commons-io-2.4.jar

还压缩了我的整个示例项目并在此处上传:

https://skydrive.live.com/redir?resid=60B826E451F52B4D!118&authkey=!ALa1n2mL2sRR0wU

编辑2:

就像 Manolo 指出的那样:我使用的是“commons-fileupload-1.3.jar”而不是“commons-fileupload-1.2.1.jar”。更换罐子解决了我的问题!

4

1 回答 1

2

问题在于您使用的 commons-fileupload 版本,将其更改为 1.2.1 版本,这是gwtupload 文档中指出的版本。

它也应该与 1.2.2 一起使用,但要使用 1.3 需要新方法 (setHeaders),这些方法不在 gwtupload 提供的 UploadListeners 中。

您应该在项目中将目标 java(JDK 合规性)更改为 1.6,因为它是 GWT 中最后一个支持以避免出现问题的版本,尽管它在 1.7 中运行。

于 2013-08-01T08:50:50.943 回答