Closed
Description
bissorc opened SPR-17030 and commented
I’m using Spring Rest Template to upload a file. Code looks as follows:
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", "2;3;4".getBytes());
MultiValueMap<String, HttpEntity<?>> body = builder.build();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.ALL));
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity(body, headers);
RestTemplate restTemplate = new RestTemplate();
restTemplate.postForLocation("***", requestEntity, String.class);
This leads to the following raw request:
POST *** HTTP/1.1
Accept: */*
Content-Type: multipart/form-data;boundary=059h2BBM-KlM_XP2rY8W1X3_jnzFLcYY;charset=UTF-8
User-Agent: Java/1.8.0_121
Host: ***:***
Connection: keep-alive
Content-Length: 187
--059h2BBM-KlM_XP2rY8W1X3_jnzFLcYY
Content-Disposition: form-data; name="file"
Content-Type: text/plain;charset=UTF-8
Content-Length: 5
2;3;4
--059h2BBM-KlM_XP2rY8W1X3_jnzFLcYY—
The problem is the following line:
Content-Type: multipart/form-data;boundary=059h2BBM-KlM_XP2rY8W1X3_jnzFLcYY;charset=UTF-8
Spring Rest Template adds ;charset=UTF-8
to the content type and this leads to problems when. I found no possibility to remove the charset. From my point of view this is a bug since the charset should not be part of the content type?!
Affects: 5.0.7
Issue Links:
- Multipart: Invalid boundary with RestTemplate [SPR-17061] #21599 Multipart: Invalid boundary with RestTemplate ("is duplicated by")