question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return image and not json

See original GitHub issue

Describe your question

Actually, I’m using Javalin as full JSON API. But, now I need to have a route that return an image, to use it in HTML side as src.

I will have base64. How can I return image that can be known when html will use http://my-link.com/image/2 ?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Dec 13, 2022

Thanks, I fixed it by using ctx.result(Base64.getDecoder().decode(img.getImage())).contentType(img.getImageType()); after removing the data:image/png;base64, part

Happy to hear that! (I would again like to encourage you to store the image as binary blob instead of doing base64-decoding on every request ☺️).

0reactions
Elikill58commented, Dec 13, 2022

Thanks, I fixed it by using ctx.result(Base64.getDecoder().decode(img.getImage())).contentType(img.getImageType()); after removing the data:image/png;base64, part

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you put an image file in a json object? - Stack Overflow
I can think of doing it in two ways: 1. Storing the file in file system in any directory (say dir1 ) and...
Read more >
How get image and correct json file in apache NiFi...
I need to send a file in jpeg format and a json string in post-request. Screenshots below By sending this - 333513.
Read more >
Describing Responses - Swagger
JSON is the most common format for data exchange, but not the only one possible. ... This operation returns image; /logo: get: summary:...
Read more >
Show Images from URLs in a JSON file using JavaScript
I am sharing an example here that explains how to show images using image URLs extracted from a JSON file in JavaScript.
Read more >
Display Icons / Images from JSON File in React JS - YouTube
Inside React JS main return statement, we take a div. ... Require image may not work here where images are defined in JSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found