John Mark opened SPR-12017 and commented
When using an InputStreamResource to upload a file for example
...
MultiValueMap<String, Object> postData = new LinkedMultiValueMap<>();
postData.add("param", "something");
postData.add("file", new InputStreamResource(in));
restTemplate.postForObject(url, postData, String.class);
This causes a strange exception to be thrown: IllegalStateException: InputStream has already been read....
Looking through the code it appears that what is occurring is when AbstractResource.contentLength() is called, it actually reads the entire InputStream. This makes it impossible to use InputStreamResource without defining the Content-Length header. It would be nice if this were not the case. Or if this is required for some reason, at least it should be documented so other people don't have to waste time debugging like I had to.
Affects: 3.2.10, 4.0.6
Issue Links:
Referenced from: commits e14aad8, 5342d92, f0bcb77
Backported to: 3.2.11
John Mark opened SPR-12017 and commented
When using an InputStreamResource to upload a file for example
This causes a strange exception to be thrown: IllegalStateException: InputStream has already been read....
Looking through the code it appears that what is occurring is when AbstractResource.contentLength() is called, it actually reads the entire InputStream. This makes it impossible to use InputStreamResource without defining the Content-Length header. It would be nice if this were not the case. Or if this is required for some reason, at least it should be documented so other people don't have to waste time debugging like I had to.
Affects: 3.2.10, 4.0.6
Issue Links:
Referenced from: commits e14aad8, 5342d92, f0bcb77
Backported to: 3.2.11