-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
RequestBodyUtil.create uses inputStream.available() as contentLength #16006
![:octocat: :octocat:](https://assets.fantasygmm.top/images/icons/emoji/octocat.png)
Comments
Do you know what method should be used instead? I PR would be appreciated :) |
![:octocat: :octocat:](https://assets.fantasygmm.top/images/icons/emoji/octocat.png)
InputStreams do not have a defined length. If you're uploading a local file within the app's container, you use |
I want to look into this one. I'm not sure how I should verify testing this. I was thinking of creating an app that creates request with different types of data and seeing what input streams are created from this request body. Not sure if this is overkill or not. |
Actually, I'm not sure if I'm the right person to look at this. I think I would need to learn more about Android. I will leave this available to anyone else that would like to work on this. |
The available() method returns the the total number of bytes in the stream when certain implementations of InputStream is used. https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#available() For example, FileInputStream returns an estimate of the number of remaining bytes that can be read (or skipped over) from the inputstream. As for other types of inputstream it is not possible to get the stream size this would result in an unpredictable behaviour, this method should return -1 by default to indicate unknown size. |
So the summary is like:
ByteArrayOutputStream xxx = new ByteArrayOutputStream();
byte[] buf = new byte[32768];
int size = 0;
while((size = inputStream.read(buf, 0, buf.length)) != -1) {
xxx.write(buf, 0, size);
}
return xxx.size();
2 is the discussion point presumably...🤔 I dug into @dantman @janicduplessis What do you think about above? I'd like to send PR but before that let me clarify to being on the same page🙇 |
If a If the |
👋 hey everyone. Thank you for raising this issue and the discussion of potential solutions here. Given the age of this issue and time since the last activity, I'm going to go ahead and close this issue for now. However; should you still like this to remain open please let me know and I'll re-open - I would suggest though tackling this via a PR instead (if someone would like to volunteer that'd be great ❤️) and having the discussion there on the various ways of resolving this issue. Thank you |
![:octocat: :octocat:](https://assets.fantasygmm.top/images/icons/emoji/octocat.png)
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
n/a
Bug
See: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java#L132
RequestBodyUtil.create(MediaType mediaType, InputStream inputStream)
usesinputStream.available()
to set thecontentLength
of the RequestBody which is wrong.https://developer.android.com/reference/java/io/InputStream.html#available()
The text was updated successfully, but these errors were encountered: