ios – Getting immutable object error when calling fetch() from React Native


I am trying to call the Fetch API to upload a file and associated data from a React Native app for iOS. The upload succeeds, but I get an error that pops up with the following message:

Error: You attempted to set the key _i with the value 1 on an object that is meant to be immutable and has been frozen., js engine: hermes

The code I am using is below. What is causing this error?

function UploadScreen({route,navigation}){
  const {videoFile,phone,drugName,timeToTake,caregiverPhoneNumber} = route.params;
  const handleUpload = async () => {
    try{
    console.log('In handleUpload');
    const videoPath = videoFile;
    const videoData = readFile(videoPath,'base64');
    const videoUri = 'file://' + videoPath;
    const video = {
      url: videoUri,
      type: 'video/mp4',
      name: 'video.mp4',
    };
    const formData = new FormData();
    formData.append('file',{uri: videoPath, name: 'video.mp4', type:'video/mp4', data:videoData});
    formData.append('sender',caregiverPhoneNumber);
    formData.append('recipient',phone);
    formData.append('timeToTake',timeToTake);
    formData.append('drugName',drugName);
    console.log('before fetch');
    
    const response = await fetch('http://10.0.0.7/MedicationAdherenceVideoServer/UploadVideoWithData.ashx',{
      method:'POST',
      body: formData,
    });
    const responseData = await response.text();
    console.log(responseData);
    Alert.alert('Medication record uploaded');
    
    navigation.navigate('Home',{phoneNumber:caregiverPhoneNumber});
  }
  catch (error){
    console.log(error.message);
    Alert.alert('Error',error.message);
    navigation.navigate('Home',{phoneNumber:caregiverPhoneNumber});
  }
  };
  useEffect(() => {
    console.log('In UploadScreen');
    handleUpload();
  },[]);
}

I was expecting the fetch() call to succeed with no errors. The fetch call does succeed in the sense that the data and video file are uploaded, but I do get an error message.

I have tried both the .then()/.catch() pattern for promises as well as the async/await pattern.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img