[英]Upload Binary file on aws s3 using java Spring
我可以使用下面的表格數據上傳文件
但是當我嘗試通過選擇二進制作為輸入來上傳文件時,出現以下錯誤;
{"timestamp":1490680735011,"status":500,"error":"Internal Server Error","exception":"org.springframework.web.multipart.MultipartException","message":"Current request is not a multipart request","path":"/uploadBinary"}
為此,我正在編寫代碼
@RequestMapping(value = "/uploadBinary", method = RequestMethod.POST)
public ResponseEntity<Object> uploadBinary(
@RequestParam("file") MultipartFile[] multipartFiles) {
try {
System.out.println("starting....");
fileService.upload(multipartFiles);
System.out.println("uploaded successfully ");
} catch (Exception ex) {
System.out.println(ex.getMessage());
return new ResponseEntity<Object>(new String(
"Something Went wrong while uploading data to server"),
HttpStatus.OK);
}
return new ResponseEntity<Object>(new String("uploaded successfully "),
HttpStatus.OK);
}
這對於上載表單數據很好,但是對於二進制選擇則不起作用。 我們如何解決這個問題?
檢查是否在spring配置文件中添加了CommonsMultipartResolver
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.