Image loading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shareme
    New Member
    • Dec 2008
    • 8

    #1

    Image loading

    Hi
    I am doing image upload in my application. I am getting the image from the FormFile .I am converting the image into byte[] and storing those image in a drive.
    But is there any possible way to store the image in the session as byte[] and then converting these bytes[] back to an image .
    For example in my application in the first page I am allowing user to upload the image and in the next page I am displaying the image for confirmation.
    So in the first page image are allowed to uploaded then in the second page images should obtained from the session .only on the confirmation page image need to be stored in the server. If it is possible please provide me the guidance for the above process.


    Thanks
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    what is the language that you are using ?

    Comment

    • shareme
      New Member
      • Dec 2008
      • 8

      #3
      Hi
      Thank you for your reply.I am using java ,jsp.
      Last edited by debasisdas; Apr 21 '09, 07:06 AM. Reason: question moved to java forum.

      Comment

      • ne0lithic
        New Member
        • Mar 2009
        • 9

        #4
        I think you could do this by creating a BufferedImage (java.awt.image .BufferedImage) . That way you don't need a byte array each time. You can save your BufferedImage as a session variable if you use:

        Code:
        BufferedImage bufferedImage = ImageIO.read(new File("somePicture.jpg"));
        session.setAttribute("myPicture",bufferedImage);
        Cheers.

        Nikhil

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by shareme
          Hi
          Thank you for your reply.I am using java ,jsp.
          So you are using web application?
          Google with "file uploading using JSP", you will find something "multipart-request" and rest you will understand. Once your file gets uploaded then you can view it on your page, if user doesn't want to keep it anymore then delete it ;)

          Comment

          • shareme
            New Member
            • Dec 2008
            • 8

            #6
            Hi
            Thank u for your reply. I used your suggestion. It works fine .Now I am using another approach here is the code.
            Action file:
            [code=java]
            HttpSession httpSession = request.getSess ion(true);
            httpSession.set Attribute("stre am",venueManage mentForm.getSel fPhoto_Path().g etInputStream() );
            [/code]

            image.jsp:

            [code=jsp]
            <%@ page import="java.io .*" %>

            <%@ page import="java.ne t.*" %>

            <%@page contentType="im age/gif" %>

            <%

            OutputStream o = response.getOut putStream();

            InputStream is = (InputStream)se ssion.getAttrib ute("stream");

            byte[] buf = new byte[32 * 1024]; // 32k buffer

            int nRead = 0;

            while( (nRead=is.read( buf)) != -1 ) {

            o.write(buf, 0, nRead);

            }

            o.flush();;

            o.close();

            return;

            %>


            [/code]

            Display Jsp:


            [code=jsp]
            <img src="<%="/admin/venueManagement/image.jsp"%>" width="300" height="337">
            [/code]

            The above process works fine .

            Comment

            Working...