D
D
danilr2020-05-01 19:29:59
JavaScript
danilr, 2020-05-01 19:29:59

How to send an image to the server emulating FormData?

The problem is the following - I need to send a picture via I wanted to send it in base64 format via FileReader(), but the server accepts it in binary format (maybe?). How can I emulate data in the same format that FormData creates?<input type="file">

// так отправляется запрос с через FormData.
data.append('windows_view', form.windows_view.value);
            data.append('preview_image', form.preview_image.files[0]);
            
            console.log('data: ', data);

            axios.post('/panel/apartment/create', data, {
                headers: {
                    'Accept': 'application/json',
                    'Accept-Language': 'en-US,en;q=0.8',
                    'Content-Type': `multipart/form-data`,
                }
            })

and so strangely shows the data that is sent via FormData, shows that it is binary. And now I need to make the same format through the FileReader so that the server skips it. How to do it?
5eac4eafb0047424687209.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question