以下方法将返回您需要在其上发布文件的回调URL。
上传网址方法
@RequestMapping(value = "/uploadurl", method = RequestMethod.GET)public String getImageUploadUrl() { modelMap.addAttribute('uploadUrl',blobstoreService.createUploadUrl("/imageupload)); return "upload";}以下是您将在其中嵌入代码的JSP代码段。我正在使用 JSTL* 将URL放入 表单标签 中。 *
JSP页面
<form action="${uploadUrl}" method="POST" enctype="multipart/form-data"> <input type="file" name="myFile" multiple="multiple" /></form>上传处理程序方法
@ResponseBody@RequestMapping(value = "/imageupload", method = RequestMethod.POST)public void getUploadedImagesUrls(HttpServletRequest request){ Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(request); List<BlobKey> blobKeys = blobs.get("myFile[]"); if (blobKeys == null) { return null; } else { for(BlobKey blobKey : blobKeys){ // ImagesService services = ImagesServiceFactory.getImagesService(); // ServingUrlOptions serve = ServingUrlOptions.Builder.withBlobKey(blobKey); // String imageUrl = services.getServingUrl(serve); BlobInfoFactory blobInfoFactory = new BlobInfoFactory(); BlobInfo info = blobInfoFactory.loadBlobInfo(blobKey); System.out.println("Image URL : "+imageUrl); System.out.println("Image FileName : "+info.getFilename()); } }}


