Hello everyone!
Please. I am trying to upload an image file to a Node server with some basic user information kind of like updating a profile. when I was updating the profile without an image/photo it works fine. but once I selected an image (on android) it gives an error saying (Network Error). but on ios, it gets uploaded but the image uploaded is showing a blank screen. because I am getting the image link as a response after it get uploaded.
I have tried to use Form Data instead of JSON. still same
here are my image picker codes:
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
if (!result.cancelled) {
this.setState({
file:result.uri
})
}
and then the form action:
const Fullname = this.state.Firstname+','+this.state.Lastname;
// process file
let localUri = this.state.file;
let filename = localUri.split('/').pop();
let match = /\.(\w+)$/.exec(filename);
let type = match ? `image/${match[1]}` : `image/jpeg`;
const url= Platform.OS === 'android'
? localUri
: localUri.replace('file://', '');
const form = new FormData();
form.append("file",{
url,
name: filename,
type:type,
});
form.append("fullName", this.state.Firstname !== null ? Fullname : this.state.Lastname);
form.append("phone", this.state.Phone);
form.append("email", this.state.Email);
my heaer:
defaultHeader = {
"Accept": "application/json",
"Cache-Control": "no-cache",
'Content-Type': "multipart/form-data'",
"authorization": ""}
I am using Fetch.
thank you
@adamjnav