-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Stream api support within a react-native project #2159
Comments
+1 |
Same issue here. I tested the following code using Jest and the function worked as intended. async function streamToString(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", (data) => {
chunks.push(data);
});
readableStream.on("end", () => {
resolve(Buffer.concat(chunks).toString('base64'))
});
readableStream.on("error", reject);
});
}
const getAvatar = async (imgUrl) => {
return axios.get(SERVER_URL + '/api/img/avatar/' + imgUrl, {
responseType: 'stream'
})
.then(async response => {
const stream = response.data;
const rawImage = await streamToString(stream);
const imageUriPrepend = "data:image/jpeg;base64,";
const image = imageUriPrepend.concat(rawImage);
return image;
})
.catch(error => {
// Handles error when no avatar is found on Azure
console.log(error)
return
})
} However, when we put it into the React Native application, we received the error:
|
HI, This issue has to do with how Axios XMLHttpRequest. It will be a client side only issue as that is when Axios uses XMLHttpRequest. In XMLHttpRequest I am going to mark this issue for v1 as it is something we need to certainly look into. |
I assume this is related to this issue in the browser. If it's using XHR in ReactNative, which I assume it is, you're out of luck. #479 Based on @wgriffin13's error above, this is the same error you will get in your web browser. |
Closed see #479 |
Describe the issue
Does axios support Stream api(https://jakearchibald.com/2016/streams-ftw/#creating-your-own-readable-stream) and that too within a react-native project.
Example Code
fetch support Stream within browser, and as axios is written over fetch hopefully it should also support Stream. Code with fetch is mentioned below
Expected behavior, if applicable
So I am expecting that axios will behave same as fetch on browser but will it work within a react-native project, because implementation of fetch is slightly different on web than within react-native environment and so may be implementation of axios(https://stackoverflow.com/questions/56207968/stream-api-with-fetch-in-a-react-native-app),
Additional context/Screenshots
It is not a bug and that too not for axios for sure. I am just expecting suggestions if someone have implemented this kind of functionality or is it possible with axios.
Thanks
The text was updated successfully, but these errors were encountered: