F
F
Farazendasss2020-03-05 13:43:24
JavaScript
Farazendasss, 2020-03-05 13:43:24

How to send an array of data to the server?

const send = new FormData();
        ImageResizer.createResizedImage(image, 600, 600, 'JPEG', 100)
            .then((res) => RNFS.readFile(res.uri, 'base64'))
            .then((res) => {
                let string = 'data:image/jpeg:base64,'.concat(res);
                send.append('link', string);
                send.append('tags', listTags); // === ['array','array','array']
                console.log(send)

               
                return axios.post('https://', send)
            })
            .then((res) => {
                const array = Object.values(res.data)
                categoryList(array);
            })
        navigation.navigate('Category')
    }


I get a photo from the user -> I convert it to base64 -> I get the tags from the state, send the photo and tags to the server.
It works fine without tags, but not with tags. Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Cheremkhin, 2020-03-05
@Farazendasss

No transformation

...
send.append('link', string);
listTags.forEach(tag => send.append('tags[]', tag);
console.log(send)
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question