简体   繁体   English

使用Spring MultipartFile和谷歌应用引擎上传文件

[英]upload a file using spring MultipartFile and google app engine

I have been trying to upload a file by using MVC and Google App engine. 我一直在尝试使用MVC和Google App引擎上传文件。 Every time i am getting the error like 每次我得到的错误就像

Expected MultipartHttpServletRequest: is a MultipartResolver configured? 预期的MultipartHttpServletRequest:是否配置了MultipartResolver?

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. 每次流程转到控制器,但能够访问使用Spring MVC和Google App引擎在jsp文件中上传的MultipartFile文件。 The two references are 这两个参考是

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

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

so any one can guide me whats the wrong in the references to resolve the issues. 所以任何人都可以指导我在解决问题的参考文献中有什么错误。

The following method will return a callback URL on which you need to post your file(s). 以下方法将返回您需要在其上发布文件的回调URL。

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. 以下是您将嵌入代码的JSP片段。 I am putting the URL in form tag using JSTL . 我使用JSTL将URL放在表单标记中。

JSP Page JSP页面

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM