2

I'm receiving a byte stream data as a response from the server. I need to save it as an image file with the extension we want.

I've tried creating a blob out of the byte stream but it seems to break/corrupt the image.

When I use the same request in cUrl using command prompt in Windows, and redirect the whole response to a file, the image seems to be written and not be corrupted.

Can you suggest a way where I can directly write the byte data to a new file without using any intermediate blob variables.

The response data from service is like below, �����JFIF�������C�

���C���h�"��������������
�������}�!1AQa"q2���#B��R��$3br�
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����������������������������������������������������������������������������������
������w�!1AQaq"2�B���� #3R�br� $4�

Thanks in advance!!!!

  • 2
    https://github.com/eligrey/FileSaver.js – cssGEEK May 26 '16 at 09:20
  • @cssGEEK - I've tried this, it uses blob data which i want to avoid as when i do it it is breaking the image data for unknow reasons. – Pradeep Keshavprakash May 26 '16 at 09:26
  • Possible duplicate of [Javascript : How to display image from byte array using Javascript or Servlet?](http://stackoverflow.com/questions/20756042/javascript-how-to-display-image-from-byte-array-using-javascript-or-servlet) – Shree29 May 26 '16 at 09:27
  • Have you used something like this document.getElementById("imagePreview").src = "data:image/png;base64," + bytes[]; – Shree29 May 26 '16 at 09:29
  • GET data:image/jpeg;base64,%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%00%10JFIF%00%01…%01%02%03%00%04%11%05%12!1A%06%13Qa%07"q%142%EF%BF%BD%EF%BF%BD%EF%BF%BD%08 net::ERR_INVALID_URL -This is the errror i get – Pradeep Keshavprakash May 26 '16 at 09:36
  • �����JFIF��`�`�����C� ���C���h�"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� -I get the response from server something like this...but is much larger. – Pradeep Keshavprakash May 26 '16 at 09:46

0 Answers0