if (!(node instanceof ContentCollection)) {
error(request, response, "Not a directory");
return null;
}
ContentCollection dir = (ContentCollection) node;
/* Check that we have a file upload request */
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart == false) {
logger.warning("[Runner] UPLOAD Bad request");
String message = "Unable to recognize upload request. Please " +
"try again.";
response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return null;
}
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();
// Parse the request
try {
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext() == true) {
FileItemStream item = iter.next();
String name = item.getName();
InputStream stream = item.openStream();
if (item.isFormField() == false) {
ContentResource child = (ContentResource)
dir.createChild(name, ContentNode.Type.RESOURCE);
File tmp = File.createTempFile("contentupload", "tmp");
RunUtil.writeToFile(stream, tmp);
child.put(tmp);
tmp.delete();