Announcement Announcement Module
Collapse
No announcement yet.
display a image from file system Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment


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

        Comment


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

          Comment

          Working...
          X