弹簧休息:请求被拒绝,因为没有找到多边界 [英] SPRING REST: The request was rejected because no multipart boundary was found

查看:116
本文介绍了弹簧休息:请求被拒绝,因为没有找到多边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个POC的春天3休息多部分文件上传。它的工作正常。但是,当我尝试与我的应用程序集成我正面临着问题。



它引发以下异常:

  org.springframework.web。 multipart.MultipartException:无法解析多部分的servlet请求; 
嵌套的异常是org.apache.commons.fileupload.FileUploadException:
请求被拒绝,因为没有找到multipart边界**

请让我知道,如果我在我的代码的任何部分是错误的。

豆:

 < bean class =org.springframework.web.servlet.view.ContentNegotiatingViewResolver> 
< property name =order value =1/>
< property name =mediaTypes>
< map>
< entry key =jsonvalue = />
< entry key =xmlvalue =application / xml/>
< entry key =filevalue =multipart / mixed/>
< / map>
< / property>
< / bean>
<! - multipart resolver - >
< bean id =multipartResolver class =org.springframework.web.multipart.commons.CommonsMultipartResolver>
<! - 其中一个可用的属性;最大文件大小(以字节为单位)>
<属性NAME =maxUpl oadSizevalue =50000000/>
< / bean>

控制器:

  @Controller 
public class MultipleFilesRecieve {
@RequestMapping(value =/ saveMultiple,method = RequestMethod.POST)
public String save(FileUploadForm uploadForm){
列出< MultipartFile> files = uploadForm.getFiles();
列表< String> fileNames = new ArrayList< String>(); ();
if(null!= files&& files.size()> 0){
for(MultipartFile multipartFile:files){
String fileName = multipartFile.getOriginalFilename();
fileNames.add(fileName);
}
}
返回multifileSuccess;


$ / code $ / pre

解决方案

问题不在你的代码中 - 这是你的要求。您在多部分请求中缺少边界。正如在规范中所说:


多部分实体的Content-Type字段需要一个参数
boundary,用于指定封装边界。
封装边界被定义为完全由两个
连字符( - ,十进制码45)组成的行,接着是来自Content-Type头部字段的边界
参数值。 / p>

的帖子也应该是有帮助的。


I did a POC for spring 3 rest multipart file upload. Its working fine. But when i tried integrating with my application i am facing issues.

It throws following exception:

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request;
nested exception is org.apache.commons.fileupload.FileUploadException:
the request was rejected because no multipart boundary was found**"

Please let me know if I am wrong in any part of my code.

Beans:

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
 <property name="order" value="1" />
 <property name="mediaTypes">
 <map>
   <entry key="json" value="application/json" />
   <entry key="xml" value="application/xml" />
   <entry key="file" value="multipart/mixed" />
 </map>
</property>
</bean>
<!-- multipart resolver -->
 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <!-- one of the properties available; the maximum file size in bytes -->
  <property name="maxUploadSize" value="50000000" />
 </bean>

Controller:

@Controller
public class MultipleFilesRecieve {
    @RequestMapping ( value = "/saveMultiple", method = RequestMethod.POST )
        public String save( FileUploadForm uploadForm ) {
        List<MultipartFile> files = uploadForm.getFiles( );
        List<String> fileNames = new ArrayList<String>( );
        if ( null != files && files.size( ) > 0 ) {
            for ( MultipartFile multipartFile : files ) {
                String fileName = multipartFile.getOriginalFilename( );
                fileNames.add( fileName );
            }
        }
        return "multifileSuccess";
    }
}

解决方案

The problem isn't in your code - it's in your request. You're missing boundary in your multipart request. As it said in specification:

The Content-Type field for multipart entities requires one parameter, "boundary", which is used to specify the encapsulation boundary. The encapsulation boundary is defined as a line consisting entirely of two hyphen characters ("-", decimal code 45) followed by the boundary parameter value from the Content-Type header field.

This and this posts should also be helpful.

这篇关于弹簧休息:请求被拒绝,因为没有找到多边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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