我正在尝试将文件上传到标准环境上的appengine blobstore。 尝试遵循google appengine for java上的指南 但是我不是使用jsp,而是使用gwt。
因此,我首先获得一个将文件发送到Appengine blobstoreService.createUploadUrl("/uploadFile")
我提交表格。
分配给路径“ / uploadFile”的servlet被调用,但是
我正在收到
java.lang.IllegalStateException: Must be called from a blob upload callback request.
at com.google.appengine.api.blobstore.BlobstoreServiceImpl.getUploads(BlobstoreServiceImpl.java:183)
at brandeira.morholt.web.server.Upload.doPost(Upload.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)...
我不直接调用该servlet,我所指的唯一一点是
blobstoreService.createUploadUrl("/uploadFile")
我的Gwt客户:
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FileUpload;
final FormPanel formPanel = new FormPanel();
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST);
final FileUpload fileUpload = new FileUpload();
panel.add(fileUpload);
Button uploadButton = new Button("carregar");
uploadButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
formPanel.submit();
}
});
panel.add(uploadButton);
myService.getBlobFileURL(projectName, fileName, new AsyncCallback<BlobURL>() {
@Override
public void onSuccess(BlobURL result) {
formPanel.setAction(result.getUrl());
}
@Override
public void onFailure(Throwable caught) {
}
});
在MyServiceImpl(RemoteServiceServlet)上:
public BlobURL getBlobFileURL(WebUser user) throws Exception {
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
return new BlobURL(blobstoreService.createUploadUrl("/uploadFile"));
}
Upload.java:
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
Map<String, List<BlobKey>> uploadedBlobs = **blobstoreService.getUploads(req)**; // exception here
我的web.xml:
<applicationContext-param>
<param-name>maxSize</param-name>
<param-value>2096000</param-value>
<!-- <param-value>1024000</param-value> -->
</applicationContext-param>
<applicationContext-param>
<param-name>corsDomainsRegex</param-name>
<param-value>.*</param-value>
</applicationContext-param>
<servlet>
<servlet-name>Uploada</servlet-name>
<servlet-class>brandeira.morholt.web.server.Upload</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Uploada</servlet-name>
<url-pattern>/uploadFile</url-pattern>
</servlet-mapping>
您能帮我吗?谢谢!