问题
I'm executing a photo upload using the fetch API and I keep receiving Type Error Network Request Error
. I receive the same error on the emulator and a device. I'm using react-native-image-crop-picker as the source for the photo upload data. Any thoughts?
const handlePhotoUpload = async (image: any, token: string) => {
const { path, filename, mime } = image;
const uri = path.replace("file://", "")
const file = {
uri,
type: mime,
name: filename
};
const body = new FormData()
body.append('file', file)
const config = {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + token },
body
};
return await fetch(`${<API URL>}/user/photo`, config)
}
回答1:
If the way you send it is Android, the way is wrong.
The correct uri is:
uri: Platform.OS === "android" ? path : path.replace("file://", "")
来源:https://stackoverflow.com/questions/58814583/photo-upload-on-react-native-android-produce-type-error-network-error