app/features/fileupload/s3/S3ServiceImpl.java
/**
     * Uploads a file's InputStream to the imagesBucket and sets the files content type in S3. The content length is
     * set to avoid memory being used by the S3Object to determine the InputStream's length. A UUID is generated for the
     * file and returned upon a successful upload.
     *
     * @param fileName   Desired name of the file to be uploaded
     * @param file       File to be uploaded
     * @param mimeType   MimeType of the file to be uploaded
     * @param bucketName String of the bucket name file will be uploaded to
     * @return Full URL of the successfully uploaded file
     * @throws FileTransferException
     */
Uploads a file's InputStream to the imagesBucket and sets the files content type in S3. The content length is
set to avoid memory being used by the S3Object to determine the InputStream's length. A UUID is generated for the
file and returned upon a successful upload.


Uploads a file ' s InputStream to the imagesBucket and sets the files content type in S3 . The content length is set to avoid memory being used by the S3Object to determine the InputStream ' s length . A UUID is generated for the file and returned upon a successful upload .
public String upload(String fileName, File file, String mimeType, String bucketName)
            throws FileTransferException {
        if (StringUtils.isEmpty(bucketName)) {
            throw new FileTransferException("No bucket name was supplied.");
        }
        try {
            S3Object s3Object = new S3Object(file);
            s3Object.setKey(fileName);
            s3Object.setContentType(mimeType);
            s3Object.setBucketName(bucketName);
            s3Object.setServerSideEncryptionAlgorithm(S3Object.SERVER_SIDE_ENCRYPTION__AES256);
            S3Object uploadedFile = s3Service.putObject(bucketName, s3Object);
            return s3BaseUrl + uploadedFile.getBucketName() + "/" + uploadedFile.getName();
        } catch (S3ServiceException e) {
            logger.error("Error when uploading file to the S3 Bucket.", e);
            throw new FileTransferException("Error when uploading file.", e);
        } catch (IOException e) {
            logger.error("Could not read in File.", e);
            throw new FileTransferException("Could not read in File.", e);
        } catch (NoSuchAlgorithmException e) {
            logger.error("Could not find correct encryption algorithm.", e);
            throw new FileTransferException("Could not find correct encryption algorithm.", e);
        }
    }
public String upload ( String fileName , File file , String mimeType , String bucketName ) throws FileTransferException { if ( StringUtils . isEmpty ( bucketName ) ) { throw new FileTransferException ( "No bucket name was supplied." ) ; } try { S3Object s3Object = new S3Object ( file ) ; s3Object . setKey ( fileName ) ; s3Object . setContentType ( mimeType ) ; s3Object . setBucketName ( bucketName ) ; s3Object . setServerSideEncryptionAlgorithm ( S3Object . SERVER_SIDE_ENCRYPTION__AES256 ) ; S3Object uploadedFile = s3Service . putObject ( bucketName , s3Object ) ; return s3BaseUrl + uploadedFile . getBucketName ( ) + "/" + uploadedFile . getName ( ) ; } catch ( S3ServiceException e ) { logger . error ( "Error when uploading file to the S3 Bucket." , e ) ; throw new FileTransferException ( "Error when uploading file." , e ) ; } catch ( IOException e ) { logger . error ( "Could not read in File." , e ) ; throw new FileTransferException ( "Could not read in File." , e ) ; } catch ( NoSuchAlgorithmException e ) { logger . error ( "Could not find correct encryption algorithm." , e ) ; throw new FileTransferException ( "Could not find correct encryption algorithm." , e ) ; } }
Uploads a file's InputStream to the imagesBucket and sets the files content type in S3.
Uploads a file ' s InputStream to the imagesBucket and sets the files content type in S3 .