Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

39
Vistas
Upload camera image to server with JavaScript

I am coding a webpage where the user can take a photo with his phone camera, then the image will be processed and stored in the server.

I am storing the image content on a <canvas> an showing it with <img> tag but I don't know how to send that information to the server.

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I just solved it by converting the canvas content into a blob and sending it to the server with fetch:

Canvas to blob

someButton.onclick = (e) => {
   //some previous code
    canvas.toBlob(upload)
}

Upload Function

function upload(blob) {
    const form = new FormData();
    form.append("img_name",blob)
    fetch("/path/to/api", {
        method:'POST',
        body:form,
    }, ).then(res => res.text()).then(resp => console.log(resp))
}

Then the server treats the file as needed.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.