0

I have had this issue for days now. I have tried several solutions with no luck. I have added below the example when the photo is taken from camera and then upload. Although the same happens if I upload it from gallery or if I upload a file. The solutions works fine on IOS but on Android it does not. I have also added mime as a library to get the correct image type since I saw that in some cases this was a problem, unfortunately for me this is not it. How can fix this?

const form_data = new FormData();
const result: ImagePicker.ImageInfo = ((await ImagePicker.launchCameraAsync()) as ImagePicker.ImageInfo);
    
      if (!result.cancelled) {
        const uriParts = result.uri.split('.');
        const fileType = uriParts[uriParts.length - 1];
         form_data.append('file', {
          uri: result.uri,
          name: result.fileName,
          type: mime.getType(result.uri),    
    });
   }
       
        const response = await fetch(`${url}/fileupload`, {
          body: form_data,
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
        });
        return response.json().then(res => res);
coder03
  • 61
  • 8

0 Answers0