• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

79
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.

almost 3 years 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.

almost 3 years 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 vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda