我正在尝试将图像上传到我在 Google App Engine 上的 REST 网络服务(使用 Jersey)。
这是我的方法:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadImage(@Context HttpServletRequest request){
BlobstoreService bs = BlobstoreServiceFactory.getBlobstoreService();
bs.createUploadUrl("/upload");
Map<String, List<BlobKey>> blobFields = bs.getUploads(request);
List<BlobKey> blobKeys = blobFields.entrySet().iterator().next().getValue();
if (blobKeys != null && !blobKeys.isEmpty()) {
BlobKey blobKey = blobKeys.get(0);
System.out.println("MY KEY: "+blobKey.getKeyString());
}
return null;
}
但我得到了这个例外:
Uncaught exception from servlet
java.lang.IllegalStateException: Must be called from a blob upload callback request.
在这条线上:
Map<String, List<BlobKey>> blobFields = bs.getUploads(request);
我哪里错了?