1

Does anyone have an idea of what this is?

base64 / binary / hex??

This is an image data, but I don't know how to display it.

enter image description here

OMIT THIS STRING as it's manually added: data:image/png; base64,

hemantmetal
  • 107
  • 10

1 Answers1

1

Try using JavaScript's image object. Like this:

let base64Img = new Image();
base64Img.src = "data:image/png;base64,*rest of data here*...";

And then you can put that image object into your HTML something like this:

document.querySelector(*yourCSSselector*).appendChild(base64Img);

Edit: You said it wasn't working so I looked into it a bit more.

I encoded this image: https://i.picsum.photos/id/78/536/354.jpg

Using the tool at https://www.base64-image.de/

I then made a codepen to display that image in a simple HTML file: https://codepen.io/seancowan-dev/pen/jOEdJvy?editors=1011

new Image(); should work if you are passing it a correctly formatted Data URI. So lets take a look at what is in your URI to make sure it is properly formatted base64.

Can you screenshot a console.log(base64Img) so we can see what's in there?

  • Can you show us what you are giving it as a source? – ExuberantSitemap Jan 23 '20 at 20:51
  • I'm getting this response from the API, so I'm not sure but it looks like it's a binary data. – hemantmetal Jan 23 '20 at 22:04
  • @hemantmetal Do you have a link to any documentation on the API? Maybe we can track down the answer that way. Once we figure out how to handle the API response properly it should be easy for you to get your images on the page. – ExuberantSitemap Jan 23 '20 at 22:21
  • Sure here it is: https://one-business-software.net/wp-content/uploads/2016/11/B1H_SrvcLayer_91.pdf 3.15.2 Getting an Item Image – hemantmetal Jan 23 '20 at 22:24
  • Are you able to contact SAP support directly regarding this? I did a quick search and just a week ago another user had similar problem with getting a weirdly encoded image response. https://stackoverflow.com/questions/59794929/sap-b1-how-to-display-fetched-image-from-itemimage Check out his post there. I suspect there may be nothing wrong with your code directly but that the response you are getting is encoded in a way SAP hasn't specified in the documentation. – ExuberantSitemap Jan 23 '20 at 22:35
  • Thanks I will do that, and will give you an upvote for your time. :) – hemantmetal Jan 24 '20 at 00:34