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 file name
     * @param mimeType    MimeType of the file to be uploaded
     * @param metaData    Metadata Map<String, Object>
     * @param inputStream InputStream to be uploaded
     * @param bucketName  String of the bucket name file will be uploaded to
     * @param folderName  String of the subfolder you want the file to be uploaded to within the passed in bucketName
     * @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, String mimeType, Map<String, Object> metaData,
                          InputStream inputStream, String bucketName, String folderName)
            throws FileTransferException {
        if (StringUtils.isEmpty(bucketName)) {
            throw new FileTransferException("No bucket name was supplied.");
        }
        try {
            S3Object s3Object = new S3Object();
            s3Object.setDataInputStream(inputStream);
            if (StringUtils.isNotBlank(folderName)) {
                s3Object.setKey(folderName + "/" + fileName);
            } else {
                s3Object.setKey(fileName);
            }
            s3Object.setContentType(mimeType);
            s3Object.addAllMetadata(metaData);
            s3Object.setBucketName(bucketName);
            s3Object.setServerSideEncryptionAlgorithm(S3Object.SERVER_SIDE_ENCRYPTION__AES256);
            S3Object uploadedFile = s3Service.putObject(bucketName, s3Object);
            return s3BaseUrl + uploadedFile.getBucketName() + "/" + uploadedFile.getKey();
        } catch (S3ServiceException e) {
            logger.error("Error when uploading file to the S3 Bucket.", e);
            throw new FileTransferException("Error when uploading file.", e);
        }
    }
public String upload ( String fileName , String mimeType , Map < String , Object > metaData , InputStream inputStream , String bucketName , String folderName ) throws FileTransferException { if ( StringUtils . isEmpty ( bucketName ) ) { throw new FileTransferException ( "No bucket name was supplied." ) ; } try { S3Object s3Object = new S3Object ( ) ; s3Object . setDataInputStream ( inputStream ) ; if ( StringUtils . isNotBlank ( folderName ) ) { s3Object . setKey ( folderName + "/" + fileName ) ; } else { s3Object . setKey ( fileName ) ; } s3Object . setContentType ( mimeType ) ; s3Object . addAllMetadata ( metaData ) ; s3Object . setBucketName ( bucketName ) ; s3Object . setServerSideEncryptionAlgorithm ( S3Object . SERVER_SIDE_ENCRYPTION__AES256 ) ; S3Object uploadedFile = s3Service . putObject ( bucketName , s3Object ) ; return s3BaseUrl + uploadedFile . getBucketName ( ) + "/" + uploadedFile . getKey ( ) ; } catch ( S3ServiceException e ) { logger . error ( "Error when uploading file to the S3 Bucket." , e ) ; throw new FileTransferException ( "Error when uploading file." , 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 .