470,593 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,593 developers. It's quick & easy.

How to show preview of uploaded files from server

Hi all...

I have file upload option in my web application. I use Struts 2.
I wanted to show a preview of the uploaded file to the user.
The uploaded file can be of any type like Image(png,jpeg,gif,etc.),

As of now the user has to download the file if he wants to see it which is
not a good idea.

By "preview" I mean, only the first page of the file if its a normal txt or pdf file
and the image in small size(may be a thumbnail) if its an image file.

It would be OK even if its not possible for other files than
image files. Preview(thumbnail size) for only image files would also be
OK, but atleast for image files that the user uploads, I have to show
the preview to user.

Hope you got the idea. Looking for some help :)
Any help would be appreciated.

Thanks and regards,
Jun 29 '09 #1
7 9094
938 Expert 512MB

First up I don't know if there is a Java solution to this but surely after the upload has taken place you know where the file is and what it is called?

If you have that information then you can display the image in a container (say a DIV) ion the web page. This could all be done using AJAX so it be presented seamlessly to the user.

That's what I would do, this would work for image files but not for other file types.

That's the best solution I can think up for this problem.

Jun 29 '09 #2
13,262 8TB
The different file types you want to preview require approaches. e.g The images require you to create scaled down versions of the images while the .pdf files require you to read the pdf document and retrieve only the first page.
Jun 30 '09 #3

Thanx a lot for your replies. I got a solution for that (showing images). Actually my problem was that i store uploaded files in one server and application in another. So whenever the image is to be shown, it has to be fetched from the file server. So I did it like for the src property of <img> tag
i gave a servlet URL which will output the image after fetching it as a byte stream from the file server. So I have the image on the page without even storing it on the app server and can be displayed in any size.

This is fine for images but for other file types I have to check. I hope there are some utilities available for getting the first 1 or 2 pages and create an image of it to show.

Thanks and Regards,
Jun 30 '09 #4
11,448 Expert 8TB
I'd take the following route: given a file type or extension a factory creates a PreviewBuilder. That builder spits out some html given a file of that specific type and an OutputStream (the destination of the html code). A DummyBuilder creates a "no preview available" preview and is created by the factory if it can't find a proper association. A simple interface does the rest ...

kind regards,

Jun 30 '09 #5
Thanx a lot for the reply.
creating a preview or showing it was not a prob for me. The image file will be stored in a server for which there is no URL to give. So simply saying, there is nothing i can give for the src of the img tag on the jsp side.
So I am calling the web service which will get the image in bytes and then
I output that using the write() method of ImageIO. This web service will be called by a servlet of which the URL is given for the src of img tag.
And now I can show the image in any size.

But for other file types I have to get something. It should generate an image of the first page. Once this image is there I can display it easily as I am doing for image files now.

Thanks and regards
Jul 1 '09 #6
HI all,

Are there any free third parties available for generating preview of files?

Thanks and Regards,
Jul 4 '09 #7
1 Bit

I have done the uploading part. Now I need to make the preview of any type of my uploaded file. And I need to put download button in that preview. If I click that it should download.

Can anyone help me on this..Coding part should be done in JAVA

Thank you in advance..
Apr 29 '21 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Martin S | last post: by
1 post views Thread by geradeaus | last post: by
3 posts views Thread by Jeff S | last post: by
1 post views Thread by Tarren | last post: by
reply views Thread by IkBenHet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.