It's by default saved in either the servlet container's memory or the temp folder, depending on the file size and the Apache Commons FileUpload configuration (see also "Filter Configuration" section of the <p:fileUpload>
chapter in PrimeFaces User's Guide).
You shouldn't worry about this at all. The servlet container and PrimeFaces know exactly what they do. You should in the command button's action method actually be saving the uploaded file contents to the location where you need it to be. You can get the uploaded file contents as an InputStream
by UploadedFile#getInputStream()
or as a byte[]
by UploadedFile#getContents()
(getting a byte[]
is potentially memory expensive in case of large files, you know, each byte
eats one byte of JVM's memory, so don't do that in case of large files).
E.g.
<p:commandButton value="Submit" action="#{fileBean.save}" ajax="false"/>
with
private UploadedFile uploadedFile;
public void save() throws IOException {
String filename = FilenameUtils.getName(uploadedFile.getFileName());
InputStream input = uploadedFile.getInputStream();
OutputStream output = new FileOutputStream(new File("/path/to/uploads", filename));
try {
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}
(FilenameUtils
and IOUtils
are from Commons IO which you should anyway already have installed in order to get <p:fileUpload>
to work)
To generate unique file names, you may find File#createTempFile()
facility helpful.
String filename = FilenameUtils.getName(uploadedFile.getFileName());
String basename = FilenameUtils.getBaseName(filename) + "_";
String extension = "." + FilenameUtils.getExtension(filename);
File file = File.createTempFile(basename, extension, "/path/to/uploads");
FileOutputStream output = new FileOutputStream(file);
// ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…