使用 spring MultipartFile 和谷歌应用引擎上传文件 [英] upload a file using spring MultipartFile and google app engine

查看:19
本文介绍了使用 spring MultipartFile 和谷歌应用引擎上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 MVC 和 Google App 引擎上传文件.每次我收到像

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

预期的 MultipartHttpServletRequest:是否配置了 MultipartResolver?

在那之后,我参考了两个教程来上传文件.每次流进入控制器,但可以使用 Spring MVC 和 Google App 引擎访问上传到 jsp 文件中的 MultipartFile 文件.这两个引用是

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.

推荐答案

以下方法将返回一个回调 URL,您需要在该 URL 上发布文件.

The following method will return a callback URL on which you need to post your file(s).

上传网址方法

@RequestMapping(value = "/uploadurl", method = RequestMethod.GET)
public String getImageUploadUrl() {
    modelMap.addAttribute('uploadUrl',blobstoreService.createUploadUrl("/imageupload));
    return "upload";
}

以下是您将嵌入代码的 JSP 片段.我正在使用 JSTL 将 URL 放在 表单标签 中.

Following is the JSP snippet where you will embed your code. I am putting the URL in form tag using JSTL.

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

这篇关于使用 spring MultipartFile 和谷歌应用引擎上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆