-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Labels
status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: enhancementA general enhancementA general enhancement
Milestone
Description
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:
- Update advice on contentLength() in subclasses of InputStreamResource #20990 Consistent treatment of InputStreamResource subclasses
- Read large data using InputStreamResource at ResourceHttpMessageConverter [SPR-13443] #18023 Read large data using InputStreamResource at ResourceHttpMessageConverter
- resttemplate multipart post with InputStreamResource not working [SPR-13571] #18147 resttemplate multipart post with InputStreamResource not working
Referenced from: commits e14aad8, 5342d92, f0bcb77
Backported to: 3.2.11
Metadata
Metadata
Assignees
Labels
status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: enhancementA general enhancementA general enhancement