Frage

I want to provide a file upload to Google App Engine with the "GWT Upload" (https://code.google.com/p/gwtupload/). During the upload I get an error. As UploadAction servlet I use the build in: gwtupload.server.gae.AppEngineUploadAction

The servlet is configured in the web.xml in the following way:

<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>

During upload the progress bar progresses some percentages and then shows the following error:

error message

But there are no more details in the logs.

The error message shows the class gwtupload.server.gae.MemCacheFileItemFactory$CacheableFileItem with the method setHeader(). That's strange because I can't find the method in that class. What's happening here?

Edit: This is basically all the custom code i use. On the server side i use the build in gwtupload.server.gae.AppEngineUploadAction servlet.

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);
        }
    };

}

In addition to that i added the following jars to my clath path:

  • 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

Also zipped my whole sample project and uploaded it here:

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

Edit 2:

Like Manolo pointed out: I was using "commons-fileupload-1.3.jar" instead of "commons-fileupload-1.2.1.jar". Changing the jar fixed my problem!

War es hilfreich?

Lösung

The problem is in the version of the commons-fileupload you are using, change it to the version 1.2.1, which is the one pointed in the gwtupload documentation.

It should work with 1.2.2 as well, but to use 1.3 requires new methods (setHeaders) which are not in the UploadListeners provided with gwtupload.

You should change in your project the target java (JDK compliance) to 1.6, since it is the last one supported in GWT to avoid problems, although it runs in 1.7.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top