@RequestPart cannot mapping string value,Required request part 'hostname' is not present
ServerCode
@PostMapping("/uploadLog")
public String uploadAnalysisLog(@RequestPart String hostname, @RequestPart MultipartFile runLog)
ClientCode
MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
form.add("runLog", fileResource);
form.add("hostname", hostname);
HttpEntity<MultiValueMap<String, Object>> body = new HttpEntity<>(form, headers);
RestTemplate restTemplate = HttpRestClient.getRestTemplateCse();
String result = restTemplate.postForObject(UPLOAD_LOG_URL, body, String.class);
Check developer guide, seems not support this usage: https://servicecomb.apache.org/references/java-chassis/zh_CN/general-development/file-upload.html
But jaxrs @FormParam can be used:
@Path("/upload2")
@POST
@Produces(MediaType.TEXT_PLAIN)
public String fileUpload2(@FormParam("file1") Part file1, @FormParam("message") String message)
sending request in Service Center is worked,but not work with CSERestTemplate
What do you mean by sending request in Service Center is worked ? Can you add an example?
network info in chrome Request URL: https://*/cse/service/uploadLog
payload: ------WebKitFormBoundary6XjKBy4C1GAEaRpH Content-Disposition: form-data; name="hostname"
7777777777 ------WebKitFormBoundary6XjKBy4C1GAEaRpH Content-Disposition: form-data; name="runLog"; filename="Bi.log" Content-Type: application/octet-stream
------WebKitFormBoundary6XjKBy4C1GAEaRpH--
response: uploadAnalysisLog succeed
seems you missed content-type, and I test it works
see https://github.com/apache/servicecomb-java-chassis/pull/3419