How can I convert image returned from API call to data URI in nodejs? [duplicate]











up vote
0
down vote

favorite













This question is an exact duplicate of:




  • NodeJS base64 image encoding not quite working


  • How to convert binary image data to URI for same image in nodejs?

    1 answer




I am making request module in nodejs to do HTTP GET for API to get image



output looks like something like as follows




"����JFIF``��C

$.' ",#(7),01444'9=82<.342��C



2!!22222222222222222222222222222222222222222222222222����"��

���}!1AQa"q2���#B��R��$3br�

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������

���w!1AQaq"2�B���� #3R�br�
$4�%�&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?��3�s�#�Ss�sN���G��޶1������������:�����%:�4�f��Lњo~��_�֓�z��ws����Vc��T)�]�
J�[�z})s�쏧�{�������_>Yx��6�}#��)#nRPA��L��^�(�K$XH�M ;���R�{�鵱�D��� >�V�T��m����9�a���}GcV����k50�Aɧ�;�3R
ӕje_j��DJ�R���qI��B�ES�
��+��v�q����i&eO��SB%��~�Si�}��*f=��g�m/jJS�1@ E.)1@�4�����*A�J�#�K;1�ּs��u{]"G��y��c�߭k|G�d��i�-�;�_����
�4�]R]��RGZƥKR�s�KtU�1<䷸���n���69^9�N��h�@�[�h�Ƞ�W3�uƃ<@i7q
�b�����'΍��^��U��ƿ�d�xJ��ٙq�������xdR��S72x5�:����=E`xV�58R�z�ҴUQ���s�'�/�?"




code I have been trying so far.



Type 1: let base64Img = Buffer.from('above-data').toString('base64')



Type 2: let base64Image = new Buffer('above-data', 'binary').toString('base64');



Type 3: Using NPM Btoa module



var b64 = btoa('above-data');


None of ways I tried are working. As in if I put output in correct URI scheme to online converter it doesn't parse back to the image.



Please suggest where I might be going wrong ? Is there any chance I am not consuming API response correctly ?










share|improve this question















marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 2:27


This question was marked as an exact duplicate of an existing question.















  • "Previous posts ..." - So this may come as a surprise to you, but the response to "... I didn't get expected answer" is NOT to keep posting the same question over and over. Instead, You can "edit your question" and provide additional details, and of course notify anyone who responded about your changes. But posting again just because you "don't like answers" or "it's taking too long for people to answer" is not an acceptable practice.
    – Neil Lunn
    Nov 20 at 2:27















up vote
0
down vote

favorite













This question is an exact duplicate of:




  • NodeJS base64 image encoding not quite working


  • How to convert binary image data to URI for same image in nodejs?

    1 answer




I am making request module in nodejs to do HTTP GET for API to get image



output looks like something like as follows




"����JFIF``��C

$.' ",#(7),01444'9=82<.342��C



2!!22222222222222222222222222222222222222222222222222����"��

���}!1AQa"q2���#B��R��$3br�

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������

���w!1AQaq"2�B���� #3R�br�
$4�%�&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?��3�s�#�Ss�sN���G��޶1������������:�����%:�4�f��Lњo~��_�֓�z��ws����Vc��T)�]�
J�[�z})s�쏧�{�������_>Yx��6�}#��)#nRPA��L��^�(�K$XH�M ;���R�{�鵱�D��� >�V�T��m����9�a���}GcV����k50�Aɧ�;�3R
ӕje_j��DJ�R���qI��B�ES�
��+��v�q����i&eO��SB%��~�Si�}��*f=��g�m/jJS�1@ E.)1@�4�����*A�J�#�K;1�ּs��u{]"G��y��c�߭k|G�d��i�-�;�_����
�4�]R]��RGZƥKR�s�KtU�1<䷸���n���69^9�N��h�@�[�h�Ƞ�W3�uƃ<@i7q
�b�����'΍��^��U��ƿ�d�xJ��ٙq�������xdR��S72x5�:����=E`xV�58R�z�ҴUQ���s�'�/�?"




code I have been trying so far.



Type 1: let base64Img = Buffer.from('above-data').toString('base64')



Type 2: let base64Image = new Buffer('above-data', 'binary').toString('base64');



Type 3: Using NPM Btoa module



var b64 = btoa('above-data');


None of ways I tried are working. As in if I put output in correct URI scheme to online converter it doesn't parse back to the image.



Please suggest where I might be going wrong ? Is there any chance I am not consuming API response correctly ?










share|improve this question















marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 2:27


This question was marked as an exact duplicate of an existing question.















  • "Previous posts ..." - So this may come as a surprise to you, but the response to "... I didn't get expected answer" is NOT to keep posting the same question over and over. Instead, You can "edit your question" and provide additional details, and of course notify anyone who responded about your changes. But posting again just because you "don't like answers" or "it's taking too long for people to answer" is not an acceptable practice.
    – Neil Lunn
    Nov 20 at 2:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question is an exact duplicate of:




  • NodeJS base64 image encoding not quite working


  • How to convert binary image data to URI for same image in nodejs?

    1 answer




I am making request module in nodejs to do HTTP GET for API to get image



output looks like something like as follows




"����JFIF``��C

$.' ",#(7),01444'9=82<.342��C



2!!22222222222222222222222222222222222222222222222222����"��

���}!1AQa"q2���#B��R��$3br�

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������

���w!1AQaq"2�B���� #3R�br�
$4�%�&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?��3�s�#�Ss�sN���G��޶1������������:�����%:�4�f��Lњo~��_�֓�z��ws����Vc��T)�]�
J�[�z})s�쏧�{�������_>Yx��6�}#��)#nRPA��L��^�(�K$XH�M ;���R�{�鵱�D��� >�V�T��m����9�a���}GcV����k50�Aɧ�;�3R
ӕje_j��DJ�R���qI��B�ES�
��+��v�q����i&eO��SB%��~�Si�}��*f=��g�m/jJS�1@ E.)1@�4�����*A�J�#�K;1�ּs��u{]"G��y��c�߭k|G�d��i�-�;�_����
�4�]R]��RGZƥKR�s�KtU�1<䷸���n���69^9�N��h�@�[�h�Ƞ�W3�uƃ<@i7q
�b�����'΍��^��U��ƿ�d�xJ��ٙq�������xdR��S72x5�:����=E`xV�58R�z�ҴUQ���s�'�/�?"




code I have been trying so far.



Type 1: let base64Img = Buffer.from('above-data').toString('base64')



Type 2: let base64Image = new Buffer('above-data', 'binary').toString('base64');



Type 3: Using NPM Btoa module



var b64 = btoa('above-data');


None of ways I tried are working. As in if I put output in correct URI scheme to online converter it doesn't parse back to the image.



Please suggest where I might be going wrong ? Is there any chance I am not consuming API response correctly ?










share|improve this question
















This question is an exact duplicate of:




  • NodeJS base64 image encoding not quite working


  • How to convert binary image data to URI for same image in nodejs?

    1 answer




I am making request module in nodejs to do HTTP GET for API to get image



output looks like something like as follows




"����JFIF``��C

$.' ",#(7),01444'9=82<.342��C



2!!22222222222222222222222222222222222222222222222222����"��

���}!1AQa"q2���#B��R��$3br�

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������

���w!1AQaq"2�B���� #3R�br�
$4�%�&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?��3�s�#�Ss�sN���G��޶1������������:�����%:�4�f��Lњo~��_�֓�z��ws����Vc��T)�]�
J�[�z})s�쏧�{�������_>Yx��6�}#��)#nRPA��L��^�(�K$XH�M ;���R�{�鵱�D��� >�V�T��m����9�a���}GcV����k50�Aɧ�;�3R
ӕje_j��DJ�R���qI��B�ES�
��+��v�q����i&eO��SB%��~�Si�}��*f=��g�m/jJS�1@ E.)1@�4�����*A�J�#�K;1�ּs��u{]"G��y��c�߭k|G�d��i�-�;�_����
�4�]R]��RGZƥKR�s�KtU�1<䷸���n���69^9�N��h�@�[�h�Ƞ�W3�uƃ<@i7q
�b�����'΍��^��U��ƿ�d�xJ��ٙq�������xdR��S72x5�:����=E`xV�58R�z�ҴUQ���s�'�/�?"




code I have been trying so far.



Type 1: let base64Img = Buffer.from('above-data').toString('base64')



Type 2: let base64Image = new Buffer('above-data', 'binary').toString('base64');



Type 3: Using NPM Btoa module



var b64 = btoa('above-data');


None of ways I tried are working. As in if I put output in correct URI scheme to online converter it doesn't parse back to the image.



Please suggest where I might be going wrong ? Is there any chance I am not consuming API response correctly ?





This question is an exact duplicate of:




  • NodeJS base64 image encoding not quite working


  • How to convert binary image data to URI for same image in nodejs?

    1 answer








node.js base64 binary-data data-uri base64url






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 3:59

























asked Nov 20 at 2:19









Royjad

94




94




marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 2:27


This question was marked as an exact duplicate of an existing question.






marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 2:27


This question was marked as an exact duplicate of an existing question.














  • "Previous posts ..." - So this may come as a surprise to you, but the response to "... I didn't get expected answer" is NOT to keep posting the same question over and over. Instead, You can "edit your question" and provide additional details, and of course notify anyone who responded about your changes. But posting again just because you "don't like answers" or "it's taking too long for people to answer" is not an acceptable practice.
    – Neil Lunn
    Nov 20 at 2:27


















  • "Previous posts ..." - So this may come as a surprise to you, but the response to "... I didn't get expected answer" is NOT to keep posting the same question over and over. Instead, You can "edit your question" and provide additional details, and of course notify anyone who responded about your changes. But posting again just because you "don't like answers" or "it's taking too long for people to answer" is not an acceptable practice.
    – Neil Lunn
    Nov 20 at 2:27
















"Previous posts ..." - So this may come as a surprise to you, but the response to "... I didn't get expected answer" is NOT to keep posting the same question over and over. Instead, You can "edit your question" and provide additional details, and of course notify anyone who responded about your changes. But posting again just because you "don't like answers" or "it's taking too long for people to answer" is not an acceptable practice.
– Neil Lunn
Nov 20 at 2:27




"Previous posts ..." - So this may come as a surprise to you, but the response to "... I didn't get expected answer" is NOT to keep posting the same question over and over. Instead, You can "edit your question" and provide additional details, and of course notify anyone who responded about your changes. But posting again just because you "don't like answers" or "it's taking too long for people to answer" is not an acceptable practice.
– Neil Lunn
Nov 20 at 2:27

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python