/** * A convenience method to create a storage object for the specified path and then delete that * object from S3 * * @param path the path to the s3 object to be deleted */ private static void deleteFromPath(String path) { S3StorageManager mgr = new S3StorageManager(); TravelLogStorageObject obj = new TravelLogStorageObject(); obj.setBucketName(uniqueBucketName); obj.setStoragePath(path); mgr.delete(obj); }
/** * Scales the incoming photo data to a thumbnail size, stores it on S3, and then returns the * storage path for the photo on S3. This method uses reduced redundancy storage to reduce storage * costs. Should there be a loss of the thumbnail data on S3, it could be regenerated from the * original full size image. * * @param photo metadata for the photo * @param photoData the raw data from the photo * @return storage path used on S3 (derived from the id of the photo and a predetermined suffix) * @throws IOException */ private static String storeThumbnail(Photo photo, byte[] photoData) throws IOException { byte[] thumbnail = scalePhoto(THUMBNAIL_LONG_EDGE, photoData); TravelLogStorageObject obj = getStorageObject(thumbnail, photo.getId() + THUMB_SUFFIX); S3StorageManager mgr = new S3StorageManager(); mgr.storePublicRead(obj, true); return obj.getAwsUrl(); }
/** * Scales the incoming photo data to a web size, stores it on S3, and then returns the storage * path for the photo on S3. This method uses reduced redundancy storage to reduce storage costs. * Should there be a loss of the data on S3, it could be regenerated from the original full size * image. * * @param photo metadata for the photo * @param photoData the raw data from the photo * @return storage path used on S3 (derived from the id of the photo and a predetermined suffix) * @throws IOException */ private static String storeWebsize(Photo photo, byte[] photoData) throws IOException { byte[] websize = scalePhoto(WEBSIZE_LONG_EDGE, photoData); TravelLogStorageObject obj = getStorageObject(websize, photo.getId() + WEBSIZE_SUFFIX); S3StorageManager mgr = new S3StorageManager(); mgr.storePublicRead(obj, true); return obj.getAwsUrl(); }
/** * Loads original photo from S3, returning the raw image data. * * @param photo the photo object specifying storage path of the original photo * @return raw image data * @throws IOException */ public static InputStream loadOriginalPhoto(Photo photo) throws IOException { S3StorageManager mgr = new S3StorageManager(); TravelLogStorageObject obj = new TravelLogStorageObject(); obj.setBucketName(uniqueBucketName); obj.setStoragePath(photo.getId() + FULLSIZE_SUFFIX); return mgr.loadInputStream(obj); }
/** * Stores the original full size image on S3, and then returns the storage path for the photo on * S3. This method uses full redundancy storage because if we lose the original there's no way to * recreate it. Also, in the event of data loss of a thumbnail or web size of the original, this * could be used to recreate the smaller images. * * @param photo metadata for the photo * @param photoData the raw data from the photo * @return storage path used on S3 (derived from the id of the photo and a predetermined suffix) * @throws IOException */ private static String storeOriginal(Photo photo, byte[] photoData) throws IOException { TravelLogStorageObject obj = getStorageObject(photoData, photo.getId() + FULLSIZE_SUFFIX); S3StorageManager mgr = new S3StorageManager(); mgr.storePublicRead(obj, false); return obj.getAwsUrl(); }