/** * Takes in an InputStream representing the submitted image file and a String representing the * submitted URL, processes and stores the image, and returns a redirect to the image's results * page. * * @param inputStream InputStream representing the image to be processed * @param url String representing the URL of the image * @return a redirect to the image's results page * @throws IOException * @throws SQLException */ @Override public String processInputStream(InputStream inputStream, String url) throws IOException, SQLException { Image image = new Image(); File tempFile = ImageOperations.streamToFile(inputStream); new ImageOperations() .fillFields(image, tempFile); // Sends image file to the DatabaseOperations object Image tempImg; try { if ((tempImg = dBOps.imageBlobAlreadyExists(image)) == null) { dBOps.addEntity(image); aPII.tagImageUrl(image, url); } else { image.setID(tempImg.getID()); } } catch (Exception e) { e.printStackTrace(); } String id = cryptoHandler.encryptId(image.getID()); return id; } /* NOTE: Change domain if switching to another server. */
/** * 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; }