Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda