Michael Wiedmann wrote:

Aaron Bartell <[EMAIL PROTECTED]> wrote:
..


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);
}
}



Thanks for all the replies!

My code now looks in general like this:

MultipartRequestWrapper r = (MultipartRequestWrapper)facesContext.getExternalContext().getRequest();
Map m = r.getFileItems();
Iterator iter = m.values().iterator();
FileItem fItem = null;
while (iter.hasNext())
{
fItem = (FileItem)iter.next();
if (!fItem.isFormField())
{
break;
}
}
if (fItem != null && !fItem.isFormField())
fItem.write(f);



I still have to look how commons-fileupload handles the temp. files, especially when and whether they got deleted.

Michael


Michael,

there are situations where the top level request wrapper is not a MultipartRequestWrapper and then you have to dig down from wrapper to wrapper until you find the MultipartRequestWrapper. But that's what the HtmlInputFileUpload component does for you. So why are you not using the component in the way I laid out in my first reply?

Besides, from my experience it's almost always a bad idea to base your stuff on a framework's internals. This will fire back on you sooner or later. Just my 2 cents.

Oliver


-- Oliver Rossmueller Software Engineer and IT-Consultant Hamburg, Germany http://www.rossmueller.com



Reply via email to