The following method will return a callback URL on which you need to post your file(s).
Upload Url Method
@RequestMapping(value = "/uploadurl", method = RequestMethod.GET)
public String getImageUploadUrl() {
modelMap.addAttribute('uploadUrl',blobstoreService.createUploadUrl("/imageupload));
return "upload";
}
Following is the JSP snippet where you will embed your code. I am putting the URL in form tag using JSTL.
JSP Page
<form action="${uploadUrl}" method="POST" enctype="multipart/form-data">
<input type="file" name="myFile" multiple="multiple" />
</form>
Upload Handler Method
@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());
}
}
}