Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
Converting base64 into a functional JPEG in Typescript/angular

I am running cropperjs on a static image in the browser(retrieved from a nodejs server in jpeg format), it returns a preview in a different image that is in base64. Im trying to take that data and save the modified image back to the server in the original jpeg format. I've tried a few different things, but this is the latest:

saveCroppedImage(){  

     var split = this.imageDestination.split(','); // parsing out data:image/png;base64,
     var croppedImage = split[1];                  // assigning the base64 to a variable
     var blob = new Blob([croppedImage],{type: 'image/jpeg'}); //changing the base64->Blob
     var file = new File([blob],'cropped.jpeg');  //theoretically changing the blob->jpeg
     this.newCroppedImage = file;
}

I then upload the file to the server and it is corrupted.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ok, so I figured it out with some help of the interweb:

This is the info I had to include with the file creation, and it did have to stay a png to work.

public file = (theBlob: Blob): File =>
    {return new File([theBlob],'croppedImage.png',{lastModified:new 
    Date().getTime(), type:'image/png'}) 
 }

saveCroppedImage() {

    var split = this.imageDestination.split(',');
    console.log(this.imageDestination)
    var croppedImage = split[1]
    this.blob = blobUtil.base64StringToBlob(croppedImage);
    this.newCroppedImage =this.file(this.blob);
    this.onFileChange();

}

about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda