code: public static Path getFile(HttpServletRequest request)
              throws IOException {
          Path result = null;
  
          // Set up the objects that do all the heavy lifting
          DiskFileItemFactory factory = new DiskFileItemFactory();
          ServletFileUpload upload = new ServletFileUpload(factory);
  
          try {
              // Read the items - this will save the values to temp files
              for (FileItem item : upload.parseRequest(request)) {
                  if (!item.isFormField()) {
                      result = Files.createTempFile("upload", ".file");
                      item.write(result.toFile());
                  }
              }
          } catch (Exception e) {
              // item.write throws a general Exception, so specialise it by wrapping with IOException
              throw new IOException("Error processing uploaded file", e);
          }
  
          return result;
      }
docs: Handles reading an uploaded file.
  
  @param request The http request.
  @return A temp file containing the file data.
  @throws IOException If an error occurs in processing the file.