Aaron Bartell wrote:

I just got done implementing that about two months ago. Here is the
code to my backing bean.  Hope it helps you.

public class MainCtl {
   UploadedFile upFile;
...

   public String upload() throws IOException {
      // This is using Hibernate to figure out what folder path
should be used to store the file.
       Sysctl sys = Sysctl.getRecord();

       FacesContext fc = FacesContext.getCurrentInstance();
       fc.getExternalContext().getApplicationMap().put("fileupload_bytes",
upFile.getBytes());
       fc.getExternalContext().getApplicationMap().put("fileupload_type",
upFile.getContentType());
       fc.getExternalContext().getApplicationMap().put("fileupload_name",
upFile.getName());

String guid = (new VMID()).toString().replaceAll(":", "");
writeFile(upFile, sys.getUploadfolder().trim() + guid);
return null;
}


   private void writeFile(UploadedFile uf, String file) throws IOException {
       InputStream is = uf.getInputStream();
       FileOutputStream fos = new FileOutputStream(file);
       int c;
       while ((c = is.read()) != -1) {
           fos.write(c);
       }
   }

   public UploadedFile getUpFile() {
       return upFile;
   }

   public void setUpFile(UploadedFile x) {
       upFile = x;
   }
}

-------jsp---------
 <x:inputFileUpload id="fileupload"
                    accept="image/*"
                    value="#{MainCtl.upFile}"
                    storage="file"
                    styleClass="input"
                    required="false"/>
<h:commandButton value="load it up" action="#{MainCtl.upload}"
styleClass="button"/>



Aaron Bartell


On Wed, 16 Feb 2005 16:33:24 +0100, Michael Wiedmann
<[EMAIL PROTECTED]> wrote:


I had a look at x:inputFileUpload but cannot figure out how to handle the once
uploaded file. I tried to follow "examples/web/fileupload.jsp" and
"examples/misc/FileUploadForm.java". It looks like the uploaded file is located
in the configured temp. space ("uploadRepositoryPath" in web.xml)

How do I transfer this to the final location (I build the pathname for the final
location for myself)?

The documentation of Jakarta commons fileUpload mentions code like:

..
FileItem item = ...;
..
item.write(uploadedFile);

All what I am missing is how to get this "FileItem".

Michael
--



Curious, could you use?
c.getExternalContext().getSessionMap()

or

c.getExternalContext().getRequestMap()

My thinking is that if I use the application map then I'll probably have to be 
sure to clear that out often or I'll have some problems?

Also, shouldn't you close your FileOutputStream in writeFile?

Thanks,
-Mark





Reply via email to