Results 1 to 5 of 5

Thread: display a image from file system

  1. #1
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default display a image from file system

    Hi

    In my application a user is able to upload his/her photo. other than that there are so many other files the user can upload.
    Once uploaded, normal files only need to be able to download, but for the photo I want to display it on the view.

    for ex. lets say if I have a image pah as /home/rukshan/test.jpg how can I display it on the view?

    please advice....

    Thanks in advance

  2. #2
    Join Date
    Oct 2008
    Posts
    5

    Default

    Quote Originally Posted by rukshan View Post
    for ex. lets say if I have a image pah as /home/rukshan/test.jpg how can I display it on the view?
    I dont know if you can do this from Spring Controller (since it returns a ModelAndView and I'm new to Spring) but from a servlet, you would have to change the content type of your response i.e "image/jpg" and write the picture in the OutputStream.

    Cyril

  3. #3
    Join Date
    Aug 2008
    Location
    odessa.ua
    Posts
    26

    Default

    Quote Originally Posted by rukshan View Post
    Hi

    In my application a user is able to upload his/her photo. other than that there are so many other files the user can upload.
    Once uploaded, normal files only need to be able to download, but for the photo I want to display it on the view.

    for ex. lets say if I have a image pah as /home/rukshan/test.jpg how can I display it on the view?

    please advice....

    Thanks in advance
    see this forum.springframework.org/showpost.php?p=92948&postcount=2 and this forum.springframework.org/showpost.php?p=93324&postcount=2

  4. #4
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    314

    Default

    Spring controller is kind of a Servlet

    You can write the stuff into the HttpServletResponse. Get the writer from there and that's it. What comes to ModelAndView return value, just return a null value. It's prohibited to write some own stuff to HttpServletResponse and return a ModelAndView object.
    if a trainstation is where the train stops, what's a workstation...

  5. #5
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default

    Quote Originally Posted by rukshan View Post
    Hi

    In my application a user is able to upload his/her photo. other than that there are so many other files the user can upload.
    Once uploaded, normal files only need to be able to download, but for the photo I want to display it on the view.
    can some one advice me what would be the best practise for above scenario. For one of my previous project what I did was I created a folder under webapps folder and saved all uploaded files in the folder I created, so I managed to display the image using <img > tag just like loading from images folder, but I feel my approach is wrong.

    My objective is to display a users details + photo.

    any advice??

    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •