簡體   English   中英

無法在Spring / Postman中上傳多部分文件和dto對象內容類型'application / octet-stream'不支持

[英]Unable to upload multipart file and dto object in Spring/Postman Content type 'application/octet-stream' not supported

我正在嘗試通過控制器發送以下請求

@RequestMapping(value = {"/fileupload"}, method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE)
    @ResponseStatus(value = HttpStatus.OK)
    @ResponseBody
    public Object fileupload(@RequestPart MultipartFile[] file,@RequestPart DTO dto) throws Exception {

    }

但我收到以下錯誤

CORSFilter HTTP Request: POST

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:226)
at org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver.resolveArgument(RequestPartMethodArgumentResolver.java:132)

我遇到同樣的問題,我使用下面的代碼在Angular上解決了這個問題。 在服務器端也可以,甚至可以刪除消耗。所有

url: 'api/import_bot',
data: {
       file: vm.file,
       DTO: new Blob([angular.toJson(DTO)], {type : 'application/json'})
}

您必須發送文件並將DTO包裝為BLOB並設置其內容類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM