List of usage examples for org.springframework.http HttpHeaders setContentDispositionFormData
public void setContentDispositionFormData(String name, @Nullable String filename)
From source file:org.springframework.cloud.netflix.zuul.FormZuulServletProxyApplicationTests.java
@Test public void postWithMultipartFile() { MultiValueMap<String, Object> form = new LinkedMultiValueMap<>(); HttpHeaders part = new HttpHeaders(); part.setContentType(MediaType.TEXT_PLAIN); part.setContentDispositionFormData("file", "foo.txt"); form.set("foo", new HttpEntity<>("bar".getBytes(), part)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.set("Transfer-Encoding", "chunked"); headers.setContentLength(-1);//from ww w . j a v a 2 s. com ResponseEntity<String> result = testRestTemplate.exchange("/zuul/simplefzspat/file", HttpMethod.POST, new HttpEntity<>(form, headers), String.class); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals("Posted! bar", result.getBody()); }