该请求被拒绝,因为没有在springboot中找到多部分边界
因为我正在尝试使用Spring引导和Web服务与邮递员Chrome附加组件。该请求被拒绝,因为没有在springboot中找到多部分边界
在邮递员content-type="multipart/form-data"
和我得到以下例外。
HTTP Status 500 - Request processing failed;
nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request;
nested exception is java.io.IOException:
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
在控制器I指定下面的代码
@ResponseBody
@RequestMapping(value = "/file", headers = "Content-Type= multipart/form-data", method = RequestMethod.POST)
public String upload(@RequestParam("name") String name,
@RequestParam(value = "file", required = true) MultipartFile file)
//@RequestParam()CommonsMultipartFile[] fileUpload
{
// @RequestMapping(value="/newDocument", , method = RequestMethod.POST)
if (!file.isEmpty()) {
try {
byte[] fileContent = file.getBytes();
fileSystemHandler.create(123, fileContent, name);
return "You successfully uploaded " + name + "!";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
在这里,我在您的要求与指定文件处理程序代码
public String create(int jonId, byte[] fileContent, String name) {
String status = "Created file...";
try {
String path = env.getProperty("file.uploadPath") + name;
File newFile = new File(path);
newFile.createNewFile();
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(newFile));
stream.write(fileContent);
stream.close();
} catch (IOException ex) {
status = "Failed to create file...";
Logger.getLogger(FileSystemHandler.class.getName()).log(Level.SEVERE, null, ex);
}
return status;
}
问题是不是在你的代码.problem。你在多部分请求中没有得到任何有限的边界。
如何获取? –
其服务器错误 500是用于服务器 没有boundry集时,服务器接收图像 –
问题是你自己设置Content-Type,让它变成空白。谷歌浏览器会为你做。多部分内容类型需要知道文件边界,并且当您删除内容类型时,邮差会自动为您执行此操作。
的“邮差 - REST客户端”是不适合做后行动设置content-type.You可以尝试使用“高级REST客户端”或其他。
此外,头被消耗更换和生产,因为春季3.1 M2,见https://spring.io/blog/2011/06/13/spring-3-1-m2-spring-mvc-enhancements。你可以直接使用produces = MediaType.MULTIPART_FORM_DATA_VALUE
。
我也面临同样的问题,而且它在邮递员工作中的唯一工作就是不工作ith其他工具,如“高级休息客户端”。我可以知道为什么吗? – Narendhran