	private void handleUploadVideo(HttpServletRequest request,
			HttpServletResponse response, HttpSession session)
			throws IOException {
		PrintWriter out = response.getWriter();
		out.println("Uploading file...");
		response.setContentType("text/plain");
		DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
		fileItemFactory.setSizeThreshold(1 * 1024 * 1024); 
		fileItemFactory.setRepository(tempDir);
		ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
		File file = null;
		try {
			List items = uploadHandler.parseRequest(request);
			Iterator itr = items.iterator();
			FileItem videoNameItem = null;
			FileItem fileItem = null;
			while (itr.hasNext()) {
				FileItem item = (FileItem) itr.next();
				if (item.isFormField()
						&& item.getFieldName().equals("new-video-name")) { 
					log.info("Form Name = \"" + item.getFieldName()
							+ "\", Value = \"" + item.getString() + "\"");
					videoNameItem = item;
				} else {
					log.info("Field Name = \"" + item.getFieldName()
							+ "\", File Name = \"" + item.getName()
							+ "\", Content type = \""
							+ item.getContentType() 
							+ "\", File Size (bytes) = \"" + item.getSize()
							+ "\"");
					fileItem = item;
				}
			}
			if (videoNameItem == null) {
				log.severe("Video name field not found in video upload form");
				return;
			}
			if (fileItem == null) {
				log.severe("File field not found in video upload form");
				return;
			}
			FileItem i = fileItem;
			file = new File(destinationDir, fileItem.getName()); 
			fileItem.write(file); 
			int projectId = getProjectIdFromSessionAttributes(session);
			String videoName = videoNameItem.getString();
			if (Security.isSafeVideoName(videoName)
					&& Security.isSafeVideo(i)
					&& Security.isUniqueVideoName(videoName, projectId)
					&& Security.videoFits(DatabaseApi.getNumberOfVideos(projectId))) {
				String videoUrl = S3Api.uploadFile(file);
				if (videoUrl != null) {
					DatabaseApi.addVideo(new Video(videoName,
							videoUrl, "/olive/images/bbb480.jpg", projectId,
							-1, -1, false)); 
					out.println("File uploaded. Please close this window and refresh the editor page.");
					out.println();
				} else {
					out.println("Upload Failed. Error uploading video to the cloud.");
					log.warning("Upload Failed. Error uploading video to the cloud.");
					return;
				}
			} else if (!Security.isSafeVideoName(videoName)) {
				out.println("Upload Failed. Video name may consist of a-z, 0-9; and must begin with a letter.");
				log.warning("Upload Failed. Video name may consist of a-z, 0-9; and must begin with a letter.");
				return;
			} else if (!Security.isUniqueVideoName(videoName, projectId)) {
				out.println("Upload Failed. Video name already exists.");
				log.warning("Upload Failed. Video name already exists.");
				return;
			} else {
				out.println("Upload Failed. Video type is invalid or maximum number of videos reached.");
				log.warning("Upload Failed. Video type is invalid or maximum number of videos reached.");
				return;
			}
		} catch (FileUploadException e) {
			log.severe("Error encountered while parsing the request in the upload handler");
			out.println("Upload failed.");
			e.printStackTrace();
		} catch (InvalidFileSizeException e) {
			log.severe("Invalid file size");
			out.println("Upload failed (invalid file size)");
			e.printStackTrace();
		} catch (Exception e) {
			log.severe("Unknown error encountered while uploading file");
			out.println("Upload failed (unknown reason).");
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
			if (file != null) {
				file.delete();
			}
		}
	}

	private void handleUploadVideo(HttpServletRequest request,
			HttpServletResponse response, HttpSession session)
			throws IOException {
		PrintWriter out = response.getWriter();
		out.println("Uploading file...");
		response.setContentType("text/plain");
		DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
		fileItemFactory.setSizeThreshold(1 * 1024 * 1024); 
		fileItemFactory.setRepository(tempDir);
		ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
		File file = null;
		try {
			List items = uploadHandler.parseRequest(request);
			Iterator itr = items.iterator();
			FileItem videoNameItem = null;
			FileItem fileItem = null;
			while (itr.hasNext()) {
				FileItem item = (FileItem) itr.next();
				if (item.isFormField()
						&& item.getFieldName().equals("new-video-name")) { 
					log.info("Form Name = \"" + item.getFieldName()
							+ "\", Value = \"" + item.getString() + "\"");
					videoNameItem = item;
				} else {
					log.info("Field Name = \"" + item.getFieldName()
							+ "\", File Name = \"" + item.getName()
							+ "\", Content type = \""
							+ item.getContentType() 
							+ "\", File Size (bytes) = \"" + item.getSize()
							+ "\"");
					fileItem = item;
				}
			}
			if (videoNameItem == null) {
				log.severe("Video name field not found in video upload form");
				return;
			}
			if (fileItem == null) {
				log.severe("File field not found in video upload form");
				return;
			}
			FileItem i = fileItem;
			file = new File(destinationDir, fileItem.getName()); 
			fileItem.write(file); 
			int projectId = getProjectIdFromSessionAttributes(session);
			String videoName = videoNameItem.getString();
			if (Security.isSafeVideoName(videoName)
					&& Security.isSafeVideo(i)
					&& Security.isUniqueVideoName(videoName, projectId)
					&& Security.videoFits(DatabaseApi.getNumberOfVideos(projectId))) {
				String videoUrl = S3Api.uploadFile(file);
				if (videoUrl != null) {
					DatabaseApi.addVideo(new Video(videoName,
							videoUrl, "/olive/images/bbb480.jpg", projectId,
							-1, -1, false)); 
					out.println("File uploaded. Please close this window and refresh the editor page.");
					out.println();
					response.sendRedirect("editor.jsp");	
				} else {
					out.println("Upload Failed. Error uploading video to the cloud.");
					log.warning("Upload Failed. Error uploading video to the cloud.");
					return;
				}
			} else if (!Security.isSafeVideoName(videoName)) {
				out.println("Upload Failed. Video name may consist of a-z, 0-9; and must begin with a letter.");
				log.warning("Upload Failed. Video name may consist of a-z, 0-9; and must begin with a letter.");
				return;
			} else if (!Security.isUniqueVideoName(videoName, projectId)) {
				out.println("Upload Failed. Video name already exists.");
				log.warning("Upload Failed. Video name already exists.");
				return;
			} else {
				out.println("Upload Failed. Video type is invalid or maximum number of videos reached.");
				log.warning("Upload Failed. Video type is invalid or maximum number of videos reached.");
				return;
			}
		} catch (FileUploadException e) {
			log.severe("Error encountered while parsing the request in the upload handler");
			out.println("Upload failed.");
			e.printStackTrace();
		} catch (InvalidFileSizeException e) {
			log.severe("Invalid file size");
			out.println("Upload failed (invalid file size)");
			e.printStackTrace();
		} catch (Exception e) {
			log.severe("Unknown error encountered while uploading file");
			out.println("Upload failed (unknown reason).");
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
			if (file != null) {
				file.delete();
			}
		}
	}
