4 Replies Latest reply on Jan 8, 2009 1:04 PM by francof

    How do I use rich:fileUpload

      I apologize if this is a heavy question

      I wanna upload a single file to my server. Using Seam's s:fileUpload would allow me to upload to a LOB in my db from what I read.

      I read the documentation here and I can't really understand on how to use this richfaces component.

      I tried

      <rich:fileUpload id="upload" listWidth="100px" listHeight="100px"
       acceptedTypes="jpg, gif, png, bmp">
      


      and after uploading, I found the file in my /tmp folder (windows)

      My questions are:

      Can I upload direct to a server folder say /myapp/images that I have write access to?
      Do I have to write code in the uploadListener to do this ?, anyone have sample code?

      In my case, I am replacing an existing image. So is possible to change the label for Add button to Replace ?

      Thanks
      Franco




        • 1. Re: How do I use rich:fileUpload
          meetoblivion

          You need to define a fileUploadListener, and implement the method public void processUpload(UploadEvent arg0).

          Here's an example implementation that I've been using:

          public void processUpload(UploadEvent arg0) {
           // TODO Auto-generated method stub
           if(arg0.isMultiUpload()){
           List<UploadItem> items = arg0.getUploadItems();
           for(UploadItem item : items)
           handleUpload(item);
           } else {
           UploadItem item = arg0.getUploadItem();
           handleUpload(item);
           }
          
           }
          


          • 2. Re: How do I use rich:fileUpload

            Thank you for your response.

            Got it, now I just need to pipe to FileInputStream ...

            I use an Oracle db - I am uploading images and I assume I can just as easy write the byte[] array to a blob.

            Franco

            • 3. Re: How do I use rich:fileUpload
              meetoblivion

              The UploadItem class has a getData method that returns a byte[]. No need for file input streams. depending on how you're interacting w/ the oracle db it should be easy (for example, if you're using TopLink or Hibernate you should be able to annotate the field).

              • 4. Re: How do I use rich:fileUpload

                I just wanna thank you for your help.

                I just got around to doing this yesterday after my winter break.

                I am using Hibernate and using your tips, I was able to get this working with no sweat.

                Regards
                Franco