By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,221 Members | 1,315 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,221 IT Pros & Developers. It's quick & easy.

How to show preview of uploaded files from server

P: 97
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.),
PDF,doc,txt,ppt,xls,html,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,
Sandeep.
Jun 29 '09 #1
Share this Question
Share on Google+
6 Replies


nathj
Expert 100+
P: 938
Hi,

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.

Cheers
nathj
Jun 29 '09 #2

10K+
P: 13,264
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

P: 97
Hi...

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,
Sandeep.
Jun 30 '09 #4

Expert 10K+
P: 11,448
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,

Jos
Jun 30 '09 #5

P: 97
Hi..
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
Sandeep.
Jul 1 '09 #6

P: 97
HI all,

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

Thanks and Regards,
Sandeep.
Jul 4 '09 #7

Post your reply

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