D
D
Dosya2022-01-29 22:36:40
JavaScript
Dosya, 2022-01-29 22:36:40

How does the transfer of a picture from the frontend to the backend work and how is it stored in the database?

Good day programmers, I have a question. For example, I loaded a picture in an input file, and how it is passed to the backend. I understand the data is transmitted through the API, through the fecth request, but I don’t really understand the pictures. Who knows please explain with the example of React js and Node js as I am writing in React

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
n1ksON, 2022-01-29
@Dasihub

https://learn.javascript.ru/file
React example:

const Component = () => {
  const fileReader = (e) => {
    let reader = new FileReader();
    const file = e.target.files[0]
    reader.readAsDataURL(file);
    reader.onload = () => {
      console.log(reader.result)
      // здесь инициализируем отправку изображения на сервер
    };
  }
  return (
    <div>
      <input type="file" accept='image/*' onChange={fileReader} />
    </div>  
  )
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question