// Store the file.
// Before do that, create upload directory if it doesn't exist.
File uploads = new File(uploadDirectory);
uploads.mkdirs();
if (!uploads.isDirectory()) {
throw new NotDirectoryException(
"'" + file.getAbsolutePath() + "' is not a directory.");
}
File attachedFile = new File(uploadDirectory, hash);
boolean isMoved = file.renameTo(attachedFile);