Изображение не сохраняется в модели django при попытке загрузки из react-native

Я пишу свое первое приложение на react-native с бэкендом django. Для того чтобы мое приложение функционировало правильно, мне нужно отправить изображение из react-native в модель django. Я пытаюсь отправить изображение и затем сохранить его в модели, но когда я проверяю в django-admin, поле изображения пусто.

heres my code-

react-native:

const [ sentI, setSentI ] = useState(null)

const sendI = async (image) => {
    const formData = new FormData()
    image_data = {
      uri : image.uri,
      name : "profileImage",
      type : 'image/jpg'
    }
    if (image != null){
      await formData.append( 'image', image.uri,)
      await formData.append( 'name', usern,)
      setSentI(formData)
      console.log('recieved')
    }
    console.log(formData)
  }


  const showImagePicker = async () => {
    
    // Ask the user for the permission to access the media library 
    const permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();

    if (permissionResult.granted === false) {
      alert("You've refused to allow this appp to access your photos!");
      return;
    }
    
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.All,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
    });

    // Explore the result
    console.log(result);

    if (!result.cancelled) {
      await setProfileImage(result);
      console.log(result.uri);
      sendI(result);
      
    }
  }

const image = () => {
    


    fetch(`http://192.168.5.234:8000/home/imagetest/`, {
      method: 'POST',
      body: {
        sentI
      }, 
  })
  .then( res => res.json())
  .then( res => {
    console.log(res)

  })
  .catch( error => console.log(error))

}

return (
    <View style={styles.scroll}>
        <ScrollView style={styles.scroll}>
      <Button onPress={showImagePicker} title="Select an image" />

      <View style={styles.imageContainer}>
        {
          profileImage !== null ? <Image
            source={{ uri: profileImage.uri }}
            style={styles.image}   
          />  
          :
          <Image style={styles.image}
            source={require('../assets/emptyProfile.png')}
          />

        }


      </View>
      </ScrollView>
      </View>
)

django-

@csrf_exempt
def imagetest(request):
    if request.method == "POST":
        print(request.POST)
        image = request.POST.get('image', False)
        user = request.POST.get('name', False)
        print(image)
        print(user)
        userid = User.objects.get(username=user).id
        profile = Profile.objects.get(id=userid)
        profile.image = image
        print('         asdfljka')
        print(profile.image)

как я могу решить эту проблему?

Вернуться на верх