Display image fetched from JSON responce in REACT










0















In my application i need to show multiple images that are loaded from the server on a client side.



This is the server response generating code(ASP.NET Core):



 //Create list of thumbnails
List<Object> thumbnails = new List<Object>();

foreach (ClosingDocument DItem in PackageConent.Documents)

DItem.GetPDFDocument();

Bitmap thumbnail = DItem.GetThumbnailPage(1);

thumbnails.Add(thumbnail);

JArray JO = JArray.FromObject(thumbnails);

response.Add(new JProperty("PdfDocuments", JO));


Then on a client side i do
console.log(data.Package.PdfDocuments1);



and get the following:
enter image description here



But how do i convert it into something that i can put into the <img src="???">



if i do the following:



var dataUrl = window.URL.createObjectURL(data.Package.PdfDocuments[1]);



TypeError: Failed to execute 'createObjectURL' on 'URL': No function
was found that matched the signature provided.




I edited the server code to return Base64 encoded image.



now when i do



var blob = atob(data.Package.PdfDocuments[1]);
console.log(blob);


i get:



enter image description here



But when i try to convert in to URL like this:



var data = window.URL.createObjectURL(blob);


i still get:




TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




Thanks!










share|improve this question
























  • I dont see the url or image base64 data in this json

    – victor zadorozhnyy
    Nov 13 '18 at 19:36











  • @victorzadorozhnyy I updated the question to reflect your suggestion

    – AnKing
    Nov 13 '18 at 19:54











  • have a read about canvas developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:00











  • and this stackoverflow.com/questions/7650587/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:01















0















In my application i need to show multiple images that are loaded from the server on a client side.



This is the server response generating code(ASP.NET Core):



 //Create list of thumbnails
List<Object> thumbnails = new List<Object>();

foreach (ClosingDocument DItem in PackageConent.Documents)

DItem.GetPDFDocument();

Bitmap thumbnail = DItem.GetThumbnailPage(1);

thumbnails.Add(thumbnail);

JArray JO = JArray.FromObject(thumbnails);

response.Add(new JProperty("PdfDocuments", JO));


Then on a client side i do
console.log(data.Package.PdfDocuments1);



and get the following:
enter image description here



But how do i convert it into something that i can put into the <img src="???">



if i do the following:



var dataUrl = window.URL.createObjectURL(data.Package.PdfDocuments[1]);



TypeError: Failed to execute 'createObjectURL' on 'URL': No function
was found that matched the signature provided.




I edited the server code to return Base64 encoded image.



now when i do



var blob = atob(data.Package.PdfDocuments[1]);
console.log(blob);


i get:



enter image description here



But when i try to convert in to URL like this:



var data = window.URL.createObjectURL(blob);


i still get:




TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




Thanks!










share|improve this question
























  • I dont see the url or image base64 data in this json

    – victor zadorozhnyy
    Nov 13 '18 at 19:36











  • @victorzadorozhnyy I updated the question to reflect your suggestion

    – AnKing
    Nov 13 '18 at 19:54











  • have a read about canvas developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:00











  • and this stackoverflow.com/questions/7650587/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:01













0












0








0








In my application i need to show multiple images that are loaded from the server on a client side.



This is the server response generating code(ASP.NET Core):



 //Create list of thumbnails
List<Object> thumbnails = new List<Object>();

foreach (ClosingDocument DItem in PackageConent.Documents)

DItem.GetPDFDocument();

Bitmap thumbnail = DItem.GetThumbnailPage(1);

thumbnails.Add(thumbnail);

JArray JO = JArray.FromObject(thumbnails);

response.Add(new JProperty("PdfDocuments", JO));


Then on a client side i do
console.log(data.Package.PdfDocuments1);



and get the following:
enter image description here



But how do i convert it into something that i can put into the <img src="???">



if i do the following:



var dataUrl = window.URL.createObjectURL(data.Package.PdfDocuments[1]);



TypeError: Failed to execute 'createObjectURL' on 'URL': No function
was found that matched the signature provided.




I edited the server code to return Base64 encoded image.



now when i do



var blob = atob(data.Package.PdfDocuments[1]);
console.log(blob);


i get:



enter image description here



But when i try to convert in to URL like this:



var data = window.URL.createObjectURL(blob);


i still get:




TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




Thanks!










share|improve this question
















In my application i need to show multiple images that are loaded from the server on a client side.



This is the server response generating code(ASP.NET Core):



 //Create list of thumbnails
List<Object> thumbnails = new List<Object>();

foreach (ClosingDocument DItem in PackageConent.Documents)

DItem.GetPDFDocument();

Bitmap thumbnail = DItem.GetThumbnailPage(1);

thumbnails.Add(thumbnail);

JArray JO = JArray.FromObject(thumbnails);

response.Add(new JProperty("PdfDocuments", JO));


Then on a client side i do
console.log(data.Package.PdfDocuments1);



and get the following:
enter image description here



But how do i convert it into something that i can put into the <img src="???">



if i do the following:



var dataUrl = window.URL.createObjectURL(data.Package.PdfDocuments[1]);



TypeError: Failed to execute 'createObjectURL' on 'URL': No function
was found that matched the signature provided.




I edited the server code to return Base64 encoded image.



now when i do



var blob = atob(data.Package.PdfDocuments[1]);
console.log(blob);


i get:



enter image description here



But when i try to convert in to URL like this:



var data = window.URL.createObjectURL(blob);


i still get:




TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




Thanks!







reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 19:54







AnKing

















asked Nov 13 '18 at 19:23









AnKingAnKing

355512




355512












  • I dont see the url or image base64 data in this json

    – victor zadorozhnyy
    Nov 13 '18 at 19:36











  • @victorzadorozhnyy I updated the question to reflect your suggestion

    – AnKing
    Nov 13 '18 at 19:54











  • have a read about canvas developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:00











  • and this stackoverflow.com/questions/7650587/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:01

















  • I dont see the url or image base64 data in this json

    – victor zadorozhnyy
    Nov 13 '18 at 19:36











  • @victorzadorozhnyy I updated the question to reflect your suggestion

    – AnKing
    Nov 13 '18 at 19:54











  • have a read about canvas developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:00











  • and this stackoverflow.com/questions/7650587/…

    – victor zadorozhnyy
    Nov 13 '18 at 20:01
















I dont see the url or image base64 data in this json

– victor zadorozhnyy
Nov 13 '18 at 19:36





I dont see the url or image base64 data in this json

– victor zadorozhnyy
Nov 13 '18 at 19:36













@victorzadorozhnyy I updated the question to reflect your suggestion

– AnKing
Nov 13 '18 at 19:54





@victorzadorozhnyy I updated the question to reflect your suggestion

– AnKing
Nov 13 '18 at 19:54













have a read about canvas developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…

– victor zadorozhnyy
Nov 13 '18 at 20:00





have a read about canvas developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…

– victor zadorozhnyy
Nov 13 '18 at 20:00













and this stackoverflow.com/questions/7650587/…

– victor zadorozhnyy
Nov 13 '18 at 20:01





and this stackoverflow.com/questions/7650587/…

– victor zadorozhnyy
Nov 13 '18 at 20:01












1 Answer
1






active

oldest

votes


















0














The issue I was having was due to the fact that i was trying to convert blob to an URL directly.



What I needed to do was to convert it to the proper file type first like this:



var blob = atob(page);
var file = new Blob(this.convertToByteArray(blob), type: "image/png" );
var imageUrl = window.URL.createObjectURL(file);

convertToByteArray(input)
var sliceSize = 512;
var bytes = ;

for (var offset = 0; offset < input.length; offset += sliceSize)
var slice = input.slice(offset, offset + sliceSize);

var byteNumbers = new Array(slice.length);

for (var i = 0; i < slice.length; i++)
byteNumbers[i] = slice.charCodeAt(i);


const byteArray = new Uint8Array(byteNumbers);

bytes.push(byteArray);


return bytes;






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288151%2fdisplay-image-fetched-from-json-responce-in-react%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The issue I was having was due to the fact that i was trying to convert blob to an URL directly.



    What I needed to do was to convert it to the proper file type first like this:



    var blob = atob(page);
    var file = new Blob(this.convertToByteArray(blob), type: "image/png" );
    var imageUrl = window.URL.createObjectURL(file);

    convertToByteArray(input)
    var sliceSize = 512;
    var bytes = ;

    for (var offset = 0; offset < input.length; offset += sliceSize)
    var slice = input.slice(offset, offset + sliceSize);

    var byteNumbers = new Array(slice.length);

    for (var i = 0; i < slice.length; i++)
    byteNumbers[i] = slice.charCodeAt(i);


    const byteArray = new Uint8Array(byteNumbers);

    bytes.push(byteArray);


    return bytes;






    share|improve this answer



























      0














      The issue I was having was due to the fact that i was trying to convert blob to an URL directly.



      What I needed to do was to convert it to the proper file type first like this:



      var blob = atob(page);
      var file = new Blob(this.convertToByteArray(blob), type: "image/png" );
      var imageUrl = window.URL.createObjectURL(file);

      convertToByteArray(input)
      var sliceSize = 512;
      var bytes = ;

      for (var offset = 0; offset < input.length; offset += sliceSize)
      var slice = input.slice(offset, offset + sliceSize);

      var byteNumbers = new Array(slice.length);

      for (var i = 0; i < slice.length; i++)
      byteNumbers[i] = slice.charCodeAt(i);


      const byteArray = new Uint8Array(byteNumbers);

      bytes.push(byteArray);


      return bytes;






      share|improve this answer

























        0












        0








        0







        The issue I was having was due to the fact that i was trying to convert blob to an URL directly.



        What I needed to do was to convert it to the proper file type first like this:



        var blob = atob(page);
        var file = new Blob(this.convertToByteArray(blob), type: "image/png" );
        var imageUrl = window.URL.createObjectURL(file);

        convertToByteArray(input)
        var sliceSize = 512;
        var bytes = ;

        for (var offset = 0; offset < input.length; offset += sliceSize)
        var slice = input.slice(offset, offset + sliceSize);

        var byteNumbers = new Array(slice.length);

        for (var i = 0; i < slice.length; i++)
        byteNumbers[i] = slice.charCodeAt(i);


        const byteArray = new Uint8Array(byteNumbers);

        bytes.push(byteArray);


        return bytes;






        share|improve this answer













        The issue I was having was due to the fact that i was trying to convert blob to an URL directly.



        What I needed to do was to convert it to the proper file type first like this:



        var blob = atob(page);
        var file = new Blob(this.convertToByteArray(blob), type: "image/png" );
        var imageUrl = window.URL.createObjectURL(file);

        convertToByteArray(input)
        var sliceSize = 512;
        var bytes = ;

        for (var offset = 0; offset < input.length; offset += sliceSize)
        var slice = input.slice(offset, offset + sliceSize);

        var byteNumbers = new Array(slice.length);

        for (var i = 0; i < slice.length; i++)
        byteNumbers[i] = slice.charCodeAt(i);


        const byteArray = new Uint8Array(byteNumbers);

        bytes.push(byteArray);


        return bytes;







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 16:20









        AnKingAnKing

        355512




        355512



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288151%2fdisplay-image-fetched-from-json-responce-in-react%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党