throw new IllegalStateException(
"ServletRequest does not contain multipart content. One possible solution is to explicitly call Form.setMultipart(true), Wicket tries its best to auto-detect multipart forms but there are certain situation where it cannot.");
}
// Configure the factory here, if desired.
ServletFileUpload fileUpload = new ServletFileUpload(factory);
// The encoding that will be used to decode the string parameters
// It should NOT be null at this point, but it may be
// especially if the older Servlet API 2.2 is used
String encoding = request.getCharacterEncoding();
// The encoding can also be null when using multipart/form-data encoded forms.
// In that case we use the [application-encoding] which we always demand using
// the attribute 'accept-encoding' in wicket forms.
if (encoding == null)
{
encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
}
// set encoding specifically when we found it
if (encoding != null)
{
fileUpload.setHeaderEncoding(encoding);
}
fileUpload.setSizeMax(maxSize.bytes());
final List<FileItem> items;
if (wantUploadProgressUpdates())
{
ServletRequestContext ctx = new ServletRequestContext(request)
{
@Override
public InputStream getInputStream() throws IOException
{
return new CountingInputStream(super.getInputStream());
}
};
totalBytes = request.getContentLength();
onUploadStarted(totalBytes);
items = fileUpload.parseRequest(ctx);
onUploadCompleted();
}
else
{
items = fileUpload.parseRequest(request);
}
// Loop through items
for (final FileItem item : items)
{