I am getting the following network error when attempting to upload/POST an image from Android. Works perfectly on iOS. Works perfectly on Android when no image included in FormData.
export function formatAvatarData(uri) {
const form = new FormData();
form.append('avatar', {
uri: uri,
type: 'file',
name: 'image.jpg',
});
return form;
}
iOS - [THIS WORKS AS EXPECTED]
uri: file:///Users/bobfriston/Library/Developer/CoreSimulator/Devices/16E84C5E-2545-408C-B870-38054DFA3471/data/Containers/Data/Application/7D2F59E5-450A-4A60-962A-D5C368DCD8DF/Documents/images/F5AD02D9-6C3E-46E5-B54E-D5C98206BAAA.jpg
ANDROID URI - [THIS GIVES NETWORK ERROR AS BELOW]
uri: content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F79/ORIGINAL/NONE/1408072274
Error: Network Error
at createError (createError.js:15)
at XMLHttpRequest.handleError (xhr.js:87)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:542)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:378)
NOTES: "react-native": "=0.42.3"
AndroidManifest.xml has these permissions included:
android.permission.INTERNET"
android.permission.SYSTEM_ALERT_WINDOW"/>
android.permission.CAMERA" />
android.permission.WRITE_EXTERNAL_STORAGE"/>
Try to change type
to image/jpeg
:
export function formatAvatarData(uri) {
const form = new FormData();
form.append('avatar', {
uri: uri,
type: 'image/jpeg', // <-- this
name: 'image.jpg',
});
return form;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With