Here i'm scaling image and saving in minImage (Buffred Image format)now how can i print that image as
BufferedImage minImage = ImageSale(buffered, minImageWidth, minImageHeight, TYPE_INT_RGB);
out.println("<img src=\""+minImage+"\">");
How to print image as thumb,please help me to resolve this issue.
You seem to have an issue with understanding the difference between a client and a server and what information they have available to each other, as well as the information that is maintained by HTML.
HTML is a plain text document, technically, it can't contain binary information (such as image data) and you really don't want to try and do this any way, as the HTML page itself should download relatively quickly.
The client HTML will need a reference to the image on the file server (or within the web servers context). This is typically done by saving the file to the server in a location which is accessible by the browser.
If you don't want to save the images to disk, then you will need to create some kind of "memory cache" which contains the key to the image, so that when the browser requests the image from the server you can look it up from the cache and return a stream of the image to the client browser.
This would require you to seed the URL with some kind of identifier that could be mapped to the cache
Related
I have a Spring Controller that converts PDFs into images (one for each page) and I need to display the images in a JSP.
Initially I thought of sending the images back as Base64 encoded strings, but I read a few posts advising against. So I tried to store the images as a temp file and send back to the JSP just the path to the files, but turns out it's not public.
As a temporary solution I am pointing the images' src to another REST method that retrieves the image and prints the content, however I would like to reduce the number of calls and have a single method that prints/returns all the images.
Basically you are working with 2 files (PDF and image), you receive PDF from one location and convert into to image and display the image in the JSP, there is mechanism called CDN, now a days cloud providers offers free image hosting with limited features such as AWS, Azure, GCP. For instance, check the below from AWS, and you can refer the path in your JSP.
This could be public with control panel settings.
https://aws.amazon.com/s3/
The best way is to return a page part (in some form) having a links for every page image).
In your controller load the PDF and retrieve the number of pages
Return the HTML with links to every page, invoking a next service
When asked for a page, create the page image if not already created
Return the page image
The presentation of those links, could be with < 1 2 3 ... > or whatever.
This probably requires some administration (PDF, images). It is likely there are some basic Spring examples.
You could optimize the process by job in the background / asynchrone preloading of the next page.
I am maybe asking a dumb question but I would like to be sure as my app is almost finished and I don't want to face some issue with viruses in the future
I have an app written in angular2 and a backend in java.
People can change their profile picture.
From my frontend I encode the picture in base64 and send it with a post to my rest api.
Server check the size of the base64 and reject it if it reached a certain size (but I also have a maxPostSize of 2MB in tomcat by default)
The base64 is then decoded with library net.iharder which transform it in bytearray
http://iharder.sourceforge.net/current/java/base64/
Once it is done I check if the file is a picture (and resize it as well) by creating a BufferedImage with
ImageIO.read(ByteArrayInputStream)
If it does not correspond to an image it returns null So I don't see the risk here as well.
Once it is done I store the picture in my server.
Any profile who consult the profile with picture will receive a base64 encoded image (corresponding to the uploaded one) and it will be displayed in an basic
<img src="myBase64"/>
Only JPG and PNG are allowed
My question is this one: Is there any risk for my server or for the end users if a guy send a file containg a virus? Or am I safe with the ImageIO reader.
Thanks in advance
If you store anything sent to you and send it back unchanged, then anything can happen. Just because ImageIO can read the image, doesn't mean that there's not something compromising in there.
However, if you resize the image, and use that, then there's pretty much no chance of anything surviving that as you're creating a brand new image from raw image bytes. JPG and (I guess) PNG files can contain meta data that's not part of the image, and those can potentially be vectors for exploits. But by creating a new image from the raw image data, you implicitly strip all of that.
From my understanding of SOAP, it's all about request and and response and it always outputs the response in a cryptic format (XML).
However, a fellow student told me to create a SOAP Service that displays images from a DB (or a folder with images) - just like we know from Tumblr/Pinterest/etc.
I just don't understand how that's possible - if at all?
I think what they mean is storing the images in a folder somewhere on the server and storing the file path to them as strings in the database. At least that's how I would do it.
You could also possibly encode the data with something like base64 and store that plus other relevant information like the content type (jpeg/gif etc) + a filename for the file to later stick together/decode to form an image.
Also, just in my personal opinion SOAP/XML is the devil, and I would personally serve the data as JSON.
I'm working on some reports on a Java web application. One of the requirements I have is to be able to export the report data as PDF. The reports are made up of several elements, mostly HTML tables and SVG charts courtesy of Highcharts.
Highcharts has a built-in function that exports their graphics to PDF, but I need a document that contains the other HTML data as well, so there's no other choice but to write my own code. Since the Highcharts graphics are created on the client-side, I need to submit their SVG output to the server in order to be able to include the images on the PDF document.
My first, perhaps naive, approach, was to have a form with a hidden input such as:
<form id="fileExport" method="POST" action="servlet/FileExportServlet">
<input type="hidden" id="svgParam" name="svgParam" />
</form>
And then I would set the hidden input's value to the graphic's svg code like this:
$("div#getPDF").live("click", function()
{
//the chart svg data is inside a div with class highcharts-container
//I copy the svg to the hidden input that I will submit
$("#svgParam").val($(".highcharts-container").html());
//submit the form with the hidden input
$("#fileExport").submit();
});
The problem I'm facing, is that apparently the SVG data is too large for the hidden input's value, so when it reaches the server it is truncated. I'm submitting the form in this fashion because I don't wan't to refresh the page in order to have the download start.
I was thinking that perhaps I could encode the SVG element as a Data URI, but I suppose that it wouldn't prevent truncation either, although it would produce a shorter string most of the time.
Does anyone know a way to transfer the SVG data back to the server? (Preferably allowing some other parameters as well)
Thanks
If your form is using the POST action, data will not get truncated.
Having said that, using a text camp to send binary data is unsettling. I would try either:
a) Sending it as a file attachment (but then probably your user would need to set the field value).
b) Sending it directly to your server (for example, using CURL), separately from your HTML
c) At the very least, keep using the hidden field but at least using encode64 with the data.
I'm trying to take a byte array directly from the DB and put it into a tooltip that takes HTML. This is for consistency as text needs to be included that will match the other text-only tooltips.
I'm ideally trying to bypass the step of saving the image to a file before loading it into an img src tag. Is there a way to load a byte array (could easily be converted into Image or ImageIcon beforehand) straight into HTML?
Make an image-serving servlet, map it to an appropriate URL and just dump the image data from the database.
Edit: by the way you can have the browser cache the images with this approach, but you to do it manually.
You need to convert the bytes to base64 encoding somehow (either on the java side or the html/javascript side). And then you can write something like This:
<img src="data:image/gif;base64,R0lGODlhUAAPAKIAAAsLav///88PD9WqsYmApmZmZtZfYmdakyH5BAQUAP8ALAA AAABQAA8AAAPbWLrc/jDKSVe4OOvNu/9gqARDSRBHegyGMahqO4R0bQcjIQ8E4BMCQc930JluyGRmdAAcdiigMLVrpTYWy5FKM1IQe+Mp+L4rphz+qIOBAUYeCY4p2tGrJZeH9y79mZsawFoaIRxF3JyiYxuHiMGb5KTkpFvZj4ZbYeCiXaiKBwnxh4fnt9e3ktgZyHhrChinONs3cFAShFF2JhvCZlG5uchYNun5eedRxMAF15XEFRXgZWWdciuM8GCmdSQ84lLQY5R14wDB5Lyon4ubwS7jx9NcV9/j5+g4JADs=" alt="" width="80" height="15" />
Note that n this case, even though you save a request to fetch the image, the image itself is not cached for future use.
You may look at this:
http://www.websiteoptimization.com/speed/tweak/inline-images/
For a workaround.