How to show preview of uploaded files from server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepk84
    New Member
    • Oct 2006
    • 97

    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.),
    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(thumbna il 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.
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    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

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      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.

      Comment

      • sandeepk84
        New Member
        • Oct 2006
        • 97

        #4
        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.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          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

          Comment

          • sandeepk84
            New Member
            • Oct 2006
            • 97

            #6
            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.

            Comment

            • sandeepk84
              New Member
              • Oct 2006
              • 97

              #7
              HI all,

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

              Thanks and Regards,
              Sandeep.

              Comment

              • maali07
                New Member
                • Apr 2021
                • 1

                #8
                Can you help me to make preview of any type of uploaded file in java?

                Hi,

                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..

                Comment

                Working...