launchImageLibrary issue for pickup file in Android
See original GitHub issuereact-native-image-picker
facing issue in launchImageLibrary
for uploading an image to server throw error Network request failed
in iOS it’s working fine it happens in Android
-
Tried below all solutions but not working
- uesCleartextTraffic=“true” to the AndroidManifest.xml file found inside the dir android/app/src/main/AndroidManifest.xml
- Commented this line // initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
in this file /android/app/src/main/java/com/{your_project}/MainApplication.java - Commented this line // builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); in his file android/app/src/debug/java/com/{your_project}/ReactNativeFlipper.java
- Updating FLIPPER version to
FLIPPER_VERSION=0.82.0
- React native version
"react-native": "0.63.3"
-
launchImageLibrary method options
let options = {
title: 'Update Profile'
allowsEditing: false,
quality: 1,
noData: true,
mediaType: "photo",
saveToPhotos:true,
storageOptions: {
skipBackup: true,
cameraRoll: false
},
};
launchImageLibrary(options, (response) => {
const mediaPath = Platform.OS == "android" ? { uri: response.uri } : response.uri;
if (response.didCancel) {
console.log('User cancelled photo picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else {
setUserProfile(mediaPath)
}
});
- API call Method
let formDataRequest = new FormData() formDataRequest.append("image", { uri: response.uri, name: 'fileName;, type: 'image/jpg'}) Api.updateProfileMedia(formDataRequest) .then(jsonResponse => { if (jsonResponse.status == true || jsonResponse.status == "true") { }else{ } }) .catch(error => { console.log("Error",error); })
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
react-native-image-picker not working in android 10
Adding the android:requestLegacyExternalStorage="true" in AndroidMenifest.xml file was worked for Android 10. Added it as property of the ...
Read more >How to pick images from Camera & Gallery in React Native app
In this post, you learned how to implement React Native Image Picker in your React Native app and pick the images from Camera...
Read more >React Native Pick Images From Camera & Gallery Example
Picking images is an essential task, learn how to pick images from the device's Camera and Gallery in React Native application.
Read more >Example of Image Picker in React Native
Image Picker in React Native using ImagePicker component with options 1. Take Image, 2. Choose From Library, 3. Choose from Custom Options.
Read more >ImagePicker - Expo Documentation
Android Device, Android Emulator, iOS Device, iOS Simulator, Web ... File size of the picked image or video, in bytes. height, number, Height...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Johan-dutoit Yes you are right but the concern is Result object provides by the library throws network request exceptions.
@dhananjay23 maybe a long shot, but you don’t happen to have “network inspection” active in react-native-debugger? Then uploads usually fails for me.