D
D
dNertyco2021-08-29 00:44:48
JavaScript
dNertyco, 2021-08-29 00:44:48

How to transfer a file to the server through js using a file reader for reading?

There is a form with a file field. After selecting the file, JS starts reading it through the file reader and sends it to the server via websockets, but the file is read crookedly, at least when reading and outputting, the file size in the system and in the output do not match and the file is read in the wrong encoding. How to fix?
Reading 612bf5b46a876366232972.png
code Field generation code for the file (without the code for combining and substituting elements in the dom)612bf5d99b45b118421933.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2021-08-29
@zkrvndm

The FileReader constructor is not designed to send files anywhere, it simply converts the file to the format you need. To send files, you need to use the FormData constructor and the fetch function , but since you didn’t even give an example of your code, it’s not possible to tell what you are doing wrong there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question