【问题标题】:Multipart file (not given condition).Error-400(bad request)多部分文件(未给出条件)。Error-400(错误请求)
【发布时间】:2019-06-28 23:58:21
【问题描述】:

我的rest api是。

@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUEpath="/{referenceNumber}")
public void updateCard(@RequestHeader(value = tenantId) String theTenantId,
@PathVariable String referenceNumber,@RequestParam(value = "card")MultipartFile multipartFile,HttpServletRequest request)

我需要在不浏览文件的情况下检查条件。

我的输入格式是

标题

租户 ID:***

正文:选择“formdata”(邮递员)、“multipart-formdata”(AdvancedRestClient)

卡片:不浏览文件

然后我在 Postman 中收到以下错误。

 {
"timestamp": 1549351840816,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.multipart.support.MissingServletRequestPartException",
"message": "Required request part 'card' is not present",
"path": "/app-1.5.0/1.5/references/34a236d7-9305-402f-959d-8c83d5ededbb"
  }

如果我在 AdvancedRest 客户端中尝试使用相同的输入

我得到了不同的错误。

  {
"timestamp": 1549352119229,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'null' not supported",
"path": "/app-1.5.0/1.5/references/34a236d7-9305-402f-959d-8c83d5ededbb" 
  
  } 

是否有任何不同输出的原因,我可以在没有的情况下检查 api 浏览文件。

【问题讨论】:

    标签: spring postman spring-restcontroller advanced-rest-client


    【解决方案1】:
    @PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUEpath="/{referenceNumber}")
    public void updateCard(@RequestHeader(value = tenantId) String theTenantId,
    @PathVariable String referenceNumber,@RequestPart(required = false,value = "card")MultipartFile multipartFile,HttpServletRequest request){
    
    }
    

    用户@RequestPart 而不是@RequestParam

    【讨论】:

    猜你喜欢
    • 2017-02-11
    • 2017-02-25
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多