vendredi 18 août 2017

why I use fetch to upload img in react don't have fileName?

I use fetch to upload images in react,my code is like below:

    let formData = new FormData();
    let file = {uri: imgdata, type: 'multipart/form-data', name: '2_resources.jpg'};
    formData.append("name", "name");
    formData.append("mobile", "18381307123");
    formData.append("content", "123654");
    formData.append("resources", file,"2_resources.jpg");//mind this line
    fetch(Config.report,
        {
            mode: 'cors',
            method: "POST",
            body: formData
        })
        .then(res => res.json())
        .then((data) => {
                console.log(data)
            }
        ).catch((err) => {
            console.log(err)
        }
    );

but,run it I get the request : the request

I have look for FormData API document on http://ift.tt/1c1a2nk it have write below: enter image description here

and the fetch used is :"isomorphic-fetch": "^2.2.1"

what should I do to use fetch upload images? thanks.




Aucun commentaire:

Enregistrer un commentaire