Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Decodificar y mostrar la imagen de la respuesta HTTP

Tengo un servlet de Java que puedo usar para descargar archivos de un servidor, que funciona perfectamente bien. Ahora me gustaría usar este servlet para mostrar imágenes en el sitio web. Después de solicitar una imagen, se aplica la función de script Java viewImage y la imagen se transmite en la response variable. La función viewImage tiene el siguiente aspecto:

 function viewImage(response) { // convert to Base64 let b64Image = btoa(unescape(encodeURIComponent(response))); // create image let imageData = document.createElement('img'); imageData.src = 'data:image/png;base64,' + b64Image; // append to site this.documentViewerDiv.appendChild(imageData); };

La response variable con los datos de la imagen toma, por ejemplo, valores como:

 �PNG \u001a \u0000\u0000\u0000 IHDR\u0000\u0000\u0000#\u0000\u0000\u0000%\u0008\u0006\u0000\u0000\u0000ȀPD\u0000\u0000\u0000\u0001sRGB\u0000��\u001c�\u0000\u0000\u0000\u0004gAMA\u0000\u0000��\u000b�a\u0005\u0000\u0000\u0000 pHYs\u0000\u0000\u000e�\u0000\u0000\u000e�\u0001�o�d\u0000\u0000\u0000>IDATXG��!\u0001\u0000 \u0000�0��\u0005\u0002@\u0001�\u0011\u0013�\u001bs��\u000b�\"Sd�L�)2E��\u0014�\"Sd�L�)2E��\u0014�\"��\u00051\\c�W\\��\u0000\u0000\u0000\u0000IEND�B`�

La respuesta no se ve tan mal, ¿verdad? Bueno, la conversión todavía no funciona correctamente y no sé qué está mal. ¿Alguien tiene una idea de dónde está mi error?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!