281 lines
12 KiB
HTML
281 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
| Generated by Apache Maven Doxia at 24 December 2018
|
|
| Rendered using Apache Maven Fluido Skin 1.3.0
|
|
-->
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta charset="iso-8859-1" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta name="author" content="Robert Burrell Donkin" />
|
|
<meta name="Date-Revision-yyyymmdd" content="20181224" />
|
|
<meta http-equiv="Content-Language" content="en" />
|
|
<title>FileUpload – Fileupload Overview</title>
|
|
|
|
<link rel="stylesheet" href="./css/bootstrap.min.css" type="text/css" />
|
|
<link rel="stylesheet" href="./css/site.css" type="text/css" />
|
|
<link rel="stylesheet" href="./css/print.css" media="print" />
|
|
|
|
<script type="text/javascript" src="./js/jquery.min.js"></script>
|
|
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
|
|
<script type="text/javascript" src="./js/prettify.min.js"></script>
|
|
<script type="text/javascript" src="./js/site.js"></script>
|
|
|
|
|
|
</head>
|
|
|
|
<body class="composite">
|
|
<a href="http://commons.apache.org/" id="bannerLeft" title="Apache Commons logo">
|
|
<img class="logo-left" src="./images/commons-logo.png" alt="Apache Commons logo"/>
|
|
</a>
|
|
<a href="index.html" id="bannerRight">
|
|
<img class="logo-right" src="images/logo.png" alt="Commons FileUpload"/>
|
|
</a>
|
|
<div class="clear"></div>
|
|
|
|
<div class="navbar">
|
|
<div class="navbar-inner">
|
|
<div class="container-fluid">
|
|
<a class="brand" href="http://commons.apache.org/proper/commons-fileupload/">Apache Commons FileUpload ™</a>
|
|
<ul class="nav">
|
|
|
|
<li id="publishDate">Last Published: 24 December 2018</li>
|
|
<li class="divider">|</li> <li id="projectVersion">Version: 1.4</li>
|
|
</ul>
|
|
<div class="pull-right"> <ul class="nav">
|
|
<li>
|
|
<a href="http://www.apachecon.com/" class="externalLink" title="ApacheCon">
|
|
ApacheCon</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://www.apache.org" class="externalLink" title="Apache">
|
|
Apache</a>
|
|
</li>
|
|
<li>
|
|
<a href="../../" title="Commons">
|
|
Commons</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container-fluid">
|
|
<table class="layout-table">
|
|
<tr>
|
|
<td class="sidebar">
|
|
<div class="well sidebar-nav">
|
|
<ul class="nav nav-list">
|
|
<li class="nav-header">Commons FileUpload</li>
|
|
<li class="none">
|
|
<a href="index.html" title="Overview">
|
|
Overview</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="using.html" title="User guide">
|
|
User guide</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="streaming.html" title="Streaming API">
|
|
Streaming API</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="faq.html" title="FAQ">
|
|
FAQ</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="javadocs/api-release/index.html" title="Javadoc (Latest release)">
|
|
Javadoc (Latest release)</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="download_fileupload.cgi" title="Download">
|
|
Download</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="security-reports.html" title="Security Reports">
|
|
Security Reports</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="mail-lists.html" title="Mailing lists">
|
|
Mailing lists</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="issue-tracking.html" title="Issue Tracking">
|
|
Issue Tracking</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="team-list.html" title="Team">
|
|
Team</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="source-repository.html" title="Source repository">
|
|
Source repository</a>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-list">
|
|
<li class="nav-header"><i class="icon-info-sign"></i>Project Documentation</li>
|
|
<li class="collapsed">
|
|
<a href="project-info.html" title="Project Information">
|
|
Project Information</a>
|
|
</li>
|
|
<li class="collapsed">
|
|
<a href="project-reports.html" title="Project Reports">
|
|
Project Reports</a>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-list">
|
|
<li class="nav-header">Commons</li>
|
|
<li class="none">
|
|
<a href="../../" title="Home">
|
|
Home</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/licenses/" class="externalLink" title="License">
|
|
License</a>
|
|
</li>
|
|
<li class="collapsed">
|
|
<a href="../../components.html" title="Components">
|
|
Components</a>
|
|
</li>
|
|
<li class="collapsed">
|
|
<a href="../../sandbox/index.html" title="Sandbox">
|
|
Sandbox</a>
|
|
</li>
|
|
<li class="collapsed">
|
|
<a href="../../dormant/index.html" title="Dormant">
|
|
Dormant</a>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-list">
|
|
<li class="nav-header">General Information</li>
|
|
<li class="none">
|
|
<a href="../../security.html" title="Security">
|
|
Security</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="../../volunteering.html" title="Volunteering">
|
|
Volunteering</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="../../patches.html" title="Contributing Patches">
|
|
Contributing Patches</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="../../building.html" title="Building Components">
|
|
Building Components</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="../../commons-parent-pom.html" title="Commons Parent Pom">
|
|
Commons Parent Pom</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="../../build-plugin/index.html" title="Commons Build Plugin">
|
|
Commons Build Plugin</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="../../releases/index.html" title="Releasing Components">
|
|
Releasing Components</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://wiki.apache.org/commons/FrontPage" class="externalLink" title="Wiki">
|
|
Wiki</a>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-list">
|
|
<li class="nav-header">ASF</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/foundation/how-it-works.html" class="externalLink" title="How the ASF works">
|
|
How the ASF works</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/foundation/getinvolved.html" class="externalLink" title="Get Involved">
|
|
Get Involved</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/dev/" class="externalLink" title="Developer Resources">
|
|
Developer Resources</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/foundation/policies/conduct.html" class="externalLink" title="Code of Conduct">
|
|
Code of Conduct</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsorship">
|
|
Sponsorship</a>
|
|
</li>
|
|
<li class="none">
|
|
<a href="http://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks">
|
|
Thanks</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div id="poweredBy">
|
|
<a href="http://www.apache.org/events/current-event.html" title="ApacheCon" class="builtBy">
|
|
<img class="builtBy" alt="ApacheCon" src="http://www.apache.org/events/current-event-125x125.png" />
|
|
</a>
|
|
<a href="http://maven.apache.org/" title="Maven" class="builtBy">
|
|
<img class="builtBy" alt="Maven" src="http://maven.apache.org/images/logos/maven-feather.png" />
|
|
</a>
|
|
</div>
|
|
</td>
|
|
<td class="content">
|
|
|
|
|
|
|
|
<div class="section">
|
|
<h2><a name="Using_FileUpload"></a>Using FileUpload</h2>
|
|
|
|
<p>
|
|
Your application should detect whether or not FileUpload should be
|
|
invoked, based on the HTTP method and the content type of the request.
|
|
</p>
|
|
|
|
<p>
|
|
Assuming that you have decided that FileUpload should be invoked, you
|
|
might write the following code to handle a file upload request:
|
|
</p>
|
|
<div class="source">
|
|
<pre>DiskFileItemFactory factory = new DiskFileItemFactory();
|
|
// Set upload parameters
|
|
factory.setSizeThreshold(MAX_MEMORY_SIZE);
|
|
factory.setRepository(new File(TEMP_DIR));
|
|
|
|
// Create a new file upload handler
|
|
ServletFileUpload upload = new ServletFileUpload( factory );
|
|
upload.setSizeMax(MAX_UPLOAD_SIZE);
|
|
|
|
// Parse the request
|
|
List<FileItem> items = upload.parseRequest(request);
|
|
|
|
// Process the uploaded fields
|
|
Iterator<FileItem> iter = items.iterator();
|
|
while (iter.hasNext()) {
|
|
FileItem item = iter.next();
|
|
|
|
if (item.isFormField()) {
|
|
processTextParameter(request, item);
|
|
} else {
|
|
processFileParameter(request, item);
|
|
}
|
|
}
|
|
</pre></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>Copyright © 2002-2018
|
|
<a href="https://www.apache.org/">The Apache Software Foundation</a>.
|
|
All Rights Reserved.</p>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|