I try upload picture to remote server. I'm using Expo React Native. There is function which I use to take and upload pic.
async function takeAndUploadPhotoAsync() {
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [4, 3],
});
if (result.cancelled) {
return;
}
let localUri = result.uri;
let filename = localUri.split("/").pop();
let match = /\.(\w+)$/.exec(filename);
let type = match ? `image/${match[1]}` : `image`;
let formData = new FormData();
formData.append("photo", { uri: localUri, name: filename, type });
return await fetch("https://rare-zebra-23.loca.lt/api", {
mode: "no-cors", // no-cors, *cors, same-origin
method: "POST",
body: formData,
headers: {
"content-type": "multipart/form-data",
},
});
} I'm using localtunel for my server. When I'm trying fetch I have this error in my console.log [Unhandled promise rejection: TypeError: Network request failed] . GET method works fine. Also I check my backend using regular web server and it worked. And also expo have FileSystem.uploadAsync() method which seems to me not working either. Maybe somebody can me explain why? or have some working example. Thanks.