上传文件的时候
SPRING REST: The request was rejected because no multipart boundary was found 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**"
以下是接口代码
@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";
}
}
以上问题,根据Stack Overflow大神所说:
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.
解决方法就是,把header中定义的 form-data 请求头删掉(Don't supply Content-Type header in the request. It will work.)