In Primefaces, uploaded files which are stored in a temp directory are not automatically deleted, once they have been read -


  • in xhtml use p:fileupload tag.
  • in session scoped bean keep reference uploadedfile.

basically doing this:

private uploadedfile uploadedfile;  public void fileupload(fileuploadevent event) throws ioexception {     uploadedfile = event.getfile(); } 

with separate button, action in session bean invoked copies uploaded file location. doing this:

file fileto =new file(“/xyz/abc.def”); files.copy(uploadedfile.getinputstream(), fileto.topath(), standardcopyoption.replace_existing); 

now situation follows:

with every upload invocation, temporary file created in temp directory. ok.

with every upload invocation, variable uploadedfile overwritten event.getfile(). therefore previous instance of uploadedfile @ time later garbage collected. primefaces uses under cover apache’s fileupload, deletes temporary file if uploadedfile garbage collected. can see works, okay too. scenario upload 1 file after other. can see in temp directory each upload new temp file created , after while (1 minute or so) magically removed, i.e. have been deleted during garbage collection. works perfectly.

at moment invoke action copies uploaded file, specific file not deleted more, when upload later other files , variable uploadedfile holds references other instances. have tried several other techniques copy file, apaches ioutils or hand made while loop reading , writing bytes , buffer. no matter try, seems @ moment start read bytes input stream obtain uploadedfile, temporary file not deleted more.

any ideas can wrong. have behavior primefaces version 3.5 version 5.2.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -