Example #1
0
  /**
   * Takes in an InputStream representing the submitted image file from the user's computer, uploads
   * the image to imgur for auto-tagging, processes and stores the image, and returns a redirect to
   * the image's results page.
   *
   * @param inputStream InputStream representing the image to be processed
   * @return a redirect to the image's results page
   * @throws IOException
   * @throws SQLException
   */
  @Override
  public String processInputStream(InputStream inputStream) throws IOException, SQLException {
    Image image = new Image();
    File tempFile = ImageOperations.streamToFile(inputStream);
    fillFields(image, tempFile);
    String imgurUploadUrl;
    Image tempImg;
    try {
      if ((tempImg = dBOps.imageBlobAlreadyExists(image)) == null) {
        dBOps.addEntity(image);
        imgurUploadUrl = aPII.uploadImage(tempFile);
        aPII.tagImageUrl(image, imgurUploadUrl);
        aPII.deleteImageFromImgur();
      } else {
        image.setID(tempImg.getID());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    String id = cryptoHandler.encryptId(image.getID());
    return id;
  }