upload a file using spring MultipartFile and google app engine

雨燕双飞 提交于 2019-11-27 08:10:06

问题


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.


回答1:


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());
        }
    }
}


来源:https://stackoverflow.com/questions/23421460/upload-a-file-using-spring-multipartfile-and-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!