A
A
Andrei1penguin12021-03-04 02:34:15
AJAX
Andrei1penguin1, 2021-03-04 02:34:15

How to send an image via ajax in pure js?

Good day, let's say there is a picture: You need to send this picture to the django server using pure js via ajax . I know how to send data, I can also create a form: But I don’t understand how to add an image to this form . ?
<img src="src">
form = new FormData();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Olga, 2021-03-04
@Avilona

var form = new FormData();
const file = new File([blob], "path/to/img.png", {  type: 'image/png' });
form.append("image",  file);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question