Expo does not send formdata image (Is null)

Hi Everybody i making a web frontend using expo SDK 39.0.2 but i have a big problem and really i not found a fix, i trying to send image like formdata to my backend but in mi backend this is null; this is not a problem of my api rest, i send a similar tequest from postman and all is’t working… but not working from formdata and I think : “this is problem with my way of to send formdata”

this is my code:

//Component code

    const imagepreview = async()=>{
        let result = await ImagePicker.launchImageLibraryAsync({
            allowsEditing: false,
            aspect: [4, 3],
            quality: 0.6,
        });
        console.log(result)
        if(result.cancelled == false){
            setImage(result.uri)
            let uriParts = result.uri.split('.');
            let fileType = uriParts[uriParts.length - 1];
            settype(fileType)
        }
    }

    const sendData = async()=>{
        // Upload the image using the fetch and FormData APIs
        let formData = await new FormData();
        // Assume "photo" is the name of the form field the server expects
        await formData.append('photo', {
            name: `photo.${type}`,
            type: `image/${type}`,
            uri: image,
          });
        const send = await user.changeprofilepicture(formData)

    }

And my class for my petition :



    async changeprofilepicture(formdata){
        console.log(formdata)
        const token = JSON.parse(localStorage.getItem('user-token'))
        let url = baseurl+'changeprofilepicture'
        let options = {
          headers: {
            'content-type': 'multipart/form-data'
          }
        }
        await axios.post(url, formdata, options) 
          await axios.post(url, {
              photo: formdata
          }, {headers : 
            {'Content-Type':undefined}})
    }

i have two http request for im triying two ways for solved my broblem but does not work
really, thanks for te answers

I Reply my same post, I Solved this, i change expo image picker for expo Document picker like this :

  const imagepreview = async()=>{
        const trye = await DocumentPicker.getDocumentAsync({type: 'image/*'})
        setFile(trye.file)
        setImage(trye.uri)
        console.log (trye)
    }
    
    
    const sendData = async()=>{
        formData.append('photo', file);
        console.log(file)
        return await fetch('http://127.0.0.1:3333/api/changeprofilepicture', {
          method: 'POST',
          body: formData,
        });

    }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.