-
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
[Only Android] fetch Error : [Network request failed] #33217
Comments
Have the same problem: [TypeError: Network request failed] System: |
Same problem : System: |
In my case, I was trying to upload a file with multipart/form-data but apparently fetch can't handle blob files. It works fine if I don't append the file but fails with an uninformative error if I do. I now use rn-fetch-blob which can handle uploading binary data. |
Any Update? Facing the Same Issue |
Any update? Same issue on any request. Neither react-native: 0.68.1 |
Any Update? Facing the Same Issue System: |
fixed
|
I have the same issue, started happening after upgrading from RN 0.66.4 to 0.70.5
I have also tried all the proposed solutions above without any success. |
I have a similar problem, If you directly use the instance of new FormData() to assemble the Form Data parameter, you will be prompted [AxiosError: Network Error]
for example:
It will prompt [AxiosError: Network Error] But I used the following two methods to make the request successful:
I don't know if the situation is the same as yours. I hope I can help you. Sorry, my English is poor |
Same as ugglr, it was working fine on RN 0.66.4 but upgrading to 0.70 caused it to stop working; same fetch request (uploading a file using FormData) works fine on iOS but throws a FETCH_ERROR on android; stringifying doesn't seem to help. |
Any update ? i'm getting this error trying send a file in request |
For me, I was able to fix this by adding a mime-type of the file to the upload (wasn't required previously or on iOS): const chunk = {
uri: `file://${file.path}`,
type: "application/octet-stream", // I wasn't including this; works if I use the proper type (e.g. image/jpeg) as well
name: file.name,
size: file.size
}
const formData = new FormData();
formData.append("Chunk", chunk);
formData.append("OtherData", data);
await axios.post("upload", formData, {
headers: {
"Content-Type": `multipart/form-data`,
},
}); Hope that helps someone |
@fwestling-lor and if i send a pdf, is the same type ?? |
because this go block on backend, the backend system only accept pdf type |
Ok this work for me thanks @fwestling-lor |
TL;DR This is strange. Over the last 2+ months, I was able to send a POST request w/ multipart/form-data where the images were undefined (when the user didn't add a file). The request goes through and reaches the backend and my server responds to the request successfully. This became apparent on the frontend when my app didnt navigate back after the request was sent since an error was thrown. Issue adding undefined values for file:
|
|
I have same issue. It works on iOS, but not on Android. By the way, sending first picture in post request fails, but second is ok, third in not etc. Nothing suggested in the sources helps |
I'm having the same issue today. It happens SOMETIMES. Other times, the image (FormData) posts and gets stored in the uploads folder (via a PHP script) just fine! Filesize doesn't seem to matter. Tried adding a 3 second delay. Did the "line 43 comment out" as well as ClearText in the Android.XML file. Pretty much tried EVERYTHING everyone has been suggesting. STILL having the problem. |
Awesome!! You saved my day!! I work with RTK Query and only had to change the type in the FormData files chunk. Indeed only on Android...on iOS is was fine before and stil is with type: "application/octet-stream" I had this problem with Expo 49 and RN 0.7.2.4 |
After countless hours battling with the same issue, I figured out the problem. I was sending a dictionary as a value for one of the form keys. JSON.stringify the key worked. Also I had an audio file in the payload. |
Spent few hours and research a bit. There's a problem on android with request url. Condition 1: Not Working on Android API: RTK Query Works well on iOS but not works on Android Condition 1: Works in both platforms API: RTK Query Works well on both platforms. |
POSIBLE SOLUTION I faced the same problem (iOS working & Android failure) and in the end it turned out to be a problem because the domain to which the request was made contained an underscore (_) character. Removing the underscore by a dash solved the problem. Previos domain Working domain If you are using a domain other than localhost and use special characters it is possible that it may fail because of this. I will update my comment if I find any additional information. I hope it helps 🙏🏻 |
For expo builds look here: |
First of all, I solve by adding this in the upload request headers.
I guess it happens with the HTTP connection.At the beginning, i use fetch ,but it throw Network request failed.And after i use rn-fetch-blob ,it throw unexpected end of stream. |
I was using |
@Liptor @DeveloperMCD I do have same problem, it fails sometimes, like 1 fail for 3-4 success requests. |
Hi @kisaragi99 Check if it works for you |
Tried your approach (changed mime type to Update. Probably the problem will not exist on a physical device. |
If the endpoint/url has underscores(_) in it you will get that error on Android. |
Thank you, but my url does not have this symbol. And the problem disappeared on production build. Just don't have time to dig in this network issue, happy that it works. |
instead of :
use :
|
I have the same problem in production enviroment when I upload large file to backend large than 5M. But the nginx config accept files more than 10M+ and it's ok when send by browsers or postman. It seems like some plugin in react-native reject the request when sending large files. I hope someone can tell me how to debug this. RN Version 0.72.8. |
Using So I ended up with an Asset like this:
I'm using RTK Query with
|
In my case, this code solved the problem. // uri: string = body.imageUri;
const fd = new FormData();
fd.append('image', {
uri,
name: uri.split('/').pop(),
type: 'image/jpeg',
} as any); When specifying |
it works,thanks |
Description
---My Code---
---Not working solution---
its too old solution my code already 0.99.0
---Error---
fetch not working only android emulators , physical device too
Version
0.66.4
Output of
npx react-native info
System:
OS: macOS 11.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 3.60 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.3.1 - /usr/local/bin/node
Yarn: Not Found
npm: 8.3.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK: Not Found
IDEs:
Android Studio: 4.2 AI-202.7660.26.42.7351085
Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
Languages:
Java: 11.0.9.1 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.4 => 0.66.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
just using fetch, axios etc... any networking tools
Snack, code example, screenshot, or link to a repository
No response
The text was updated successfully, but these errors were encountered: