Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Once you have the file on the server, either in memory or in a local or temp file (that depends on the framework or libraries that you're using), you will have a reference of a wrapper type.</p> <p>If you are using <a href="http://commons.apache.org/proper/commons-fileupload/index.html" rel="nofollow">Apache Commons File Upload</a>, you have a <a href="http://commons.apache.org/proper/commons-fileupload/apidocs/org/apache/commons/fileupload/FileItem.html" rel="nofollow"><code>FileItem</code></a> reference. For request all contents of the file as byte array:</p> <pre><code>byte[] contents = fileItem.get(); </code></pre> <p>If you are using <a href="http://myfaces.apache.org/trinidad/devguide/fileUpload.html" rel="nofollow">Tomahawk of Trinidad</a>, you have a <a href="http://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/model/UploadedFile.html" rel="nofollow"><code>org.apache.myfaces.trinidad.model.UploadedFile</code></a> reference. For request all contents of the file as byte array, you can use class <a href="http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/IOUtils.html" rel="nofollow"><code>IOUtils</code></a> of the <a href="http://commons.apache.org/proper/commons-io/" rel="nofollow">Apache Commons IO</a>: </p> <pre><code>byte[] contents = IOUtils.toByteArray(uploadedFile.getInputStream()); </code></pre> <p>Of if you have a reference of <a href="http://myfaces.apache.org/tomahawk-project/tomahawk/apidocs/org/apache/myfaces/custom/fileupload/UploadedFile.html" rel="nofollow"><code>org.apache.myfaces.custom.fileupload.UploadedFile</code></a>, is more simple:</p> <pre><code>byte[] contents = uploadedFile.getBytes(); </code></pre> <p><strong>UPDATE</strong></p> <p>If you are using Java EE 6, you can use new features of Server 3.0 specification for upload files without extra libraries. See the excellent tutorial of BalusC in <a href="http://balusc.blogspot.mx/2009/12/uploading-files-in-servlet-30.html" rel="nofollow">The BalusC Code: Uploading files in Servlet 3.0</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload