servicecomb-java-chassis
servicecomb-java-chassis copied to clipboard
文件上传 附件为空的时候 SDK 会将content-type设置为application/x-www-form-urlencoded
当服务端为外置tomcat的时候报 org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded
涉及的类org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl
走读源码发现:
当formMap != null 时候,
当文件上传的附件为空的时候,不走doEndWithUpload()方法
是什么现象? https://github.com/apache/servicecomb-java-chassis/issues/2400 这个问题吗?
提供端接口定义: @PostMapping(path = "/upload", consumes = MediaType.MULTIPART_FORM_DATA) public String fileUpload(@RequestPart MultipartFile file, @RequestPart(value = "name", required = true) String name) { System.out.println(name); return "Upload success ..."; 消费端 调用逻辑: HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); params.put("name", "fjw"); HttpEntity<Map<String, Object>> entity = new HttpEntity<>(params, headers); String url = "cse://gray-svc/rest/file/upload?name=fjw"; String forObject = restTemplate.postForObject(url, entity, String.class);
fixed