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

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

问题描述

我一直试图通过使用MVC和Google App引擎来上传文件。每当我收到像

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

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

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



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



所以任何人都可以引导我在解决问题时引用了什么错误问题。

解决方案

以下方法将返回您需要发布文件的回调URL。



上传网址方法

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

以下是您的JSP片段将嵌入您的代码。我正在使用 JSTL 放置在表单标记中。
$ b

JSP页

 < form action =$ {uploadUrl}method =POSTenctype =multipart / form-data> 
< input type =filename =myFilemultiple =multiple/>
< / form>

上传处理程序方法

  @ResponseBody 
@RequestMapping(value =/ imageupload,method = RequestMethod.POST)
public void getUploadedImagesUrls(HttpServletRequest request){
Map< String,List< BlobKey>> blobs = blobstoreService.getUploads(request);
列表< 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());
}
}
}


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.

解决方案

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

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

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