uploadParser.setSizeMax(uploadSize);
// Parse the request
try {
FileItemIterator iter = uploadParser.getItemIterator(ureq.getHttpReq());
while (iter.hasNext()) {
FileItemStream item = iter.next();
String itemName = item.getFieldName();
InputStream itemStream = item.openStream();
if (item.isFormField()) {
// Normal form item
// analog to ureq.getParameter in non-multipart mode
String value = Streams.asString(itemStream, "UTF-8");
addRequestParameter(itemName, value);
} else {
// File item, store it to temp location
String fileName = item.getName();
// Cleanup IE filenames that are absolute
int slashpos = fileName.lastIndexOf("/");
if (slashpos != -1) fileName = fileName.substring(slashpos + 1);
slashpos = fileName.lastIndexOf("\\");
if (slashpos != -1) fileName = fileName.substring(slashpos + 1);
File tmpFile = new File(WebappHelper.getUserDataRoot() + "/tmp/" + CodeHelper.getGlobalForeverUniqueID());
try {
FileUtils.save(itemStream, tmpFile);
// Only save non-empty file transfers, ignore empty transfers
// (e.g. already submitted in a previous form submit, not an error!)
if (tmpFile.length() > 0) {
// Save file and also original file name
requestMultipartFiles.put(itemName, tmpFile);
requestMultipartFileNames.put(itemName, fileName);
requestMultipartFileMimeTypes.put(itemName, item.getContentType());
} else {
if (tmpFile.exists()) tmpFile.delete();
}
} catch (OLATRuntimeException e) {
// Could not save stream for whatever reason, cleanup temp file and delegate exception