Question

I have been trying to upload a file by using MVC and Google App engine. Every time i am getting the error like

Expected MultipartHttpServletRequest: is a MultipartResolver configured?

After that i have referred two tutorials to upload a file. Everytime the flow goes to the controller but can able to get access to the MultipartFile file that is uploaded in the jsp file using Spring MVC and Google App engine. The two references are

http://alasdoo.com/2010/10/how-to-upload-a-file-with-spring-mvc-3-and-google-app-engine/

https://code.google.com/p/gmultipart/

so any one can guide me whats the wrong in the references to resolve the issues.

Was it helpful?

Solution

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());
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top