servicecomb-java-chassis icon indicating copy to clipboard operation
servicecomb-java-chassis copied to clipboard

文件上传 附件为空的时候 SDK 会将content-type设置为application/x-www-form-urlencoded

Open fanjiwang1992 opened this issue 3 years ago • 3 comments

当服务端为外置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

fanjiwang1992 avatar Aug 23 '21 06:08 fanjiwang1992

涉及的类org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl 走读源码发现: 当formMap != null 时候, image 当文件上传的附件为空的时候,不走doEndWithUpload()方法 image

fanjiwang1992 avatar Aug 23 '21 06:08 fanjiwang1992

是什么现象? https://github.com/apache/servicecomb-java-chassis/issues/2400 这个问题吗?

liubao68 avatar Aug 23 '21 06:08 liubao68

提供端接口定义: @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);

fanjiwang1992 avatar Aug 23 '21 09:08 fanjiwang1992

fixed

liubao68 avatar Nov 10 '23 03:11 liubao68