I’m trying to create a multipart/formdata request from within a vaadin 10 web app using a Spring-boot RestTemplate, but it always fail with 400 bad request error , I created a seperate spring web app and included the same code within that app and i was able to successfully execute the rest call so i can assume code is working fine.
[https://github.com/vaadin/vaadin-upload-flow/issues/84]
(http://) - i think this issue is somewhat related to my problem.
@RequestMapping(method = RequestMethod.POST, consumes = { "multipart/form-data" },value = "/submit")
public ResponseEntity securedAcceptJob(
@RequestParam(value = "files" , required = false)MultipartFile multipartFile,
@RequestParam(value = "name" , required = true) String name
) throws NotInitializedException,CouldNotSendException {}
public void submitResponse(SrResultEntity srResultEntity){
String path = "des/submit";
LinkedMultiValueMap<String,Object> requestEntity = new LinkedMultiValueMap<>();
requestEntity.add("name",srResultEntity.getTitle());
requestEntity.add("files",getUserFileResource());
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.ACCEPT,MediaType.APPLICATION_JSON_UTF8_VALUE);
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<LinkedMultiValueMap<String,Object>> httpEntity = new HttpEntity(requestEntity, headers);
URI uri = UriComponentsBuilder.fromUriString(buildPath(path)).buildAndExpand(pathVariables).toUri();
final ResponseEntity<String> stringResponseEntity =
restClientHelper.getRestTemplate().exchange(uri,HttpMethod.POST, httpEntity, String.class);
}
public static Resource getUserFileResource() throws IOException {
//todo replace tempFile with a real file
Path tempFile = Files.createTempFile("upload-test-file", ".txt");
Files.write(tempFile, "some test content...\nline1\nline2".getBytes());
System.out.println("uploading: " + tempFile);
File file = tempFile.toFile();
//to upload in-memory bytes use ByteArrayResource instead
return new FileSystemResource(file);
}
i tried changing the application property file by enabling
spring.servlet.multipart.enabled=true this didn’t work so i created MultipartResolver bean with
- 1)CommonsMultipartResolver
- 2)StandardServletMultipartResolver
both implementations didn’t solve the issue so i excluded the MultipartAutoConfiguration from spring app since this disable Servlet 3.x multipart support found from here [https://github.com/spring-projects/spring-boot/issues/7735]
(http://)
@EnableAutoConfiguration(exclude = {
MultipartAutoConfiguration.class // excluded so that the application uses commons-fileupload instead of Servlet 3 Multipart support
})
nothing worked for me , what am i doing wrong does anyone know how to fix this issue.is it something with Vaadin Spring module (vaadin-spring-boot-starter) does it overrides a core piece of Spring Boot in the context of the dispatcher servlet.