FileUpload - Access to Raw Stream

UI Components for JSF
Post Reply
dennisPrime
Posts: 2
Joined: 22 Sep 2014, 20:56

22 Sep 2014, 21:03

Hey everyone,

Is there anyway to access the raw/original file stream from a client's machine via PrimeFaces (4.0.x, JSF 2.1)? Currently it appears that PrimeFaces uses a FileUploadFilter that leverages apache-commons fileupload and writes the item to disk first (assume a file size of 10MB) in a temporary location. This is an unnecessary step however as most applications will then write the file to another/final location, at which point the file has been written to disk twice.

Is there anyway to avoid this behavior and prevent the file being written to a temporary location and instead pass along the raw/original input stream to the JSF managed bean?

Thanks!

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

24 Sep 2014, 12:23

The reason that an upload is written to a tmp file if its length exceeds a specified value is to prevent overly large files causing your heap space to run out.
If you don't want this feature read the User Guide about how to set the file length after which files are written to tmp. I don't advise this though, because you will end up with unpredictable and fatal heap space problems.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

dennisPrime
Posts: 2
Joined: 22 Sep 2014, 20:56

24 Sep 2014, 15:30

andyba wrote:The reason that an upload is written to a tmp file if its length exceeds a specified value is to prevent overly large files causing your heap space to run out.
If you don't want this feature read the User Guide about how to set the file length after which files are written to tmp. I don't advise this though, because you will end up with unpredictable and fatal heap space problems.
I'm not looking to store the file in memory (for the reasons you listed, e.g. 100MB file) -- I'm trying to access to the original stream of bytes coming from the client so I can write them to disk once, and only once. Right now the FileUploadFilter will either store the file in memory, or write it to a temporary location.

I'm looking for a 3rd option, like this: http://commons.apache.org/proper/common ... aming.html, that is compatible with PF and the fileUpload tag.

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

24 Sep 2014, 16:36

I think this is not compatible with the jsf lifecycles. Just use the temp file, copy that efficiently (not using the getContents()) and remove the temp file. Very efficiently and will perforn good unless you have many users and little hd space (but you then have a different problem imo)

lpenet
Posts: 71
Joined: 13 Feb 2012, 19:36
Location: Paris area, France
Contact:

18 Apr 2017, 11:11

Hi dennisPrime.

Did you manage to get the Apache Commons FileUpload streaming API working with PF (or even bare JSF) ?
Software Developer at Le Sénat - http://www.senat.fr/lng/en/index.html

When using PrimeFaces :
  • PrimeFaces Elite 5.2.5
  • MyFaces 2.2.8
  • OpenWebBeans 1.5.0
  • Deltaspike 1.3.0
  • Tomcat 8.0.23

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests