-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update advice on contentLength() in subclasses of InputStreamResource #20990
Comments
Juergen Hoeller commented What specifically are you asking for here? I'm aware that such special handling is unusual but unfortunately there is no sensible way to determine the content length for a plain Are you trying to implement such a custom |
bademus commented Thanks for quick answer, Actually I have to subclass InputStreamResource to extend metadata. I was confused a lot when my application change its behavior after I switch InputStreamResource to MyInputStreamResource. |
Juergen Hoeller commented Before #16633, So for a custom There is indeed a legacy problem here: specifically, that |
I encountered the same problem but this code below works for me. import org.springframework.core.io.ByteArrayResource;
import org.springframework.web.multipart.MultipartFile;
public class MultipartFileResource extends ByteArrayResource {
private String filename;
private long contentLength;
public MultipartFileResource(MultipartFile multipartFile) throws IOException {
super(multipartFile.getBytes());
this.filename = multipartFile.getOriginalFilename();
this.contentLength = multipartFile.getSize();
}
@Override
public String getFilename() {
return this.filename;
}
@Override
public long contentLength() {
return this.contentLength;
}
} |
bademus opened SPR-16445 and commented
It seems the bug was introduced in #16633
org.springframework.http.converter.ResourceHttpMessageConverter#getContentLength
In fact default behavior of InputStreamResource is not the same as for its children.
Affects: 4.3.14
Issue Links:
The text was updated successfully, but these errors were encountered: