webtier@glassfish.java.net

Re: where to store uploaded files

From: <webtier_at_javadesktop.org>
Date: Wed, 27 Oct 2010 19:52:29 PDT

Supposing you've got a byte stream of an inputted image, perhaps produced
by p:fileUpload, then you need to write it to a file or database in order for
h:graphicImage to display it. I have some code that will write to a disk file if
you're not using a database. Anyway, given the byte stream you need to put
it somewhere for graphicImage to display it. Use the return from loadFile
.getName() or whatever it is and you're in business.

[code]private static final String tempDir =
            "C:\\Users\\Username\\Documents\\NetBeansProjects\\MyProj\\build\\web\\resources\\images\\temp";
[/code]

[code]public File loadFile(byte[] b) throws Exception {
        File tempFile = File.createTempFile("dbload", ".jpg", new File(tempDir));
        FileOutputStream fos = new FileOutputStream(tempFile);
        fos.write(b);
        fos.close();
        return tempFile;
    }[/code]

Regards,
Brendan.
[Message sent by forum member 'healeyb']

http://forums.java.net/jive/thread.jspa?messageID=486398