我想通過「GWT上傳」(https://code.google.com/p/gwtupload/)向Google App Engine提供文件上傳。在上傳期間,我收到一個錯誤。作爲UploadAction
servlet的我用的是構建在:gwtupload.server.gae.AppEngineUploadAction
GWT上傳失敗App引擎
該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.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);
}
};
}
此外,我增加了以下罐子我clath路徑:
- 的log4j-1.2.17.jar
- gwtupload-GAE-0.6.6.jar
- gwtupload -0.6.6.jar
- 公地文件上傳-1.3.jar
- 公地-IO-2.4.jar
還拉上我的整個樣本項目,並在這裏上傳吧:
https://skydrive.live.com/redir?resid=60B826E451F52B4D!118&authkey=!ALa1n2mL2sRR0wU
編輯2:
像莫羅指出:我使用 「公地文件上傳-1.3.jar」,而不是「commons-fileupload-1.2.1.jar」。更換jar修復了我的問題!
你可以分享你的項目還是小有莫名其妙的問題,這樣我就可以安裝它,弄清楚發生了什麼事? –
另一個問題,它的開發模式也失敗,或者只是在督促GAE服務器? –
@Manolo:我在這裏上傳了示例項目:https://skydrive.live.com/redir?resid=60B826E451F52B4D!118&authkey=!ala1n2mL2sRR0wU – jan