app/features/fileupload/s3/S3ServiceImpl.java
/**
     * Uploads a File to the supplied bucketName and sets the files content type in S3. The content length is
     * set to avoid memory being used by the S3Object to determine the File'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 mimeType   MimeType of the file to be uploaded
     * @param metaData   Metadata Map<String, Object>
     * @param file       File 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 to the supplied bucketName and sets the files content type in S3. The content length is
set to avoid memory being used by the S3Object to determine the File's length. A UUID is generated for the
file and returned upon a successful upload.


Uploads a File to the supplied bucketName and sets the files content type in S3 . The content length is set to avoid memory being used by the S3Object to determine the File ' 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, File file,
                          String bucketName, String folderName)
            throws FileTransferException {
        if (StringUtils.isEmpty(bucketName)) {
            throw new FileTransferException("No bucket name was supplied.");
        }
        try {
            S3Object s3Object = new S3Object(file);
            if (StringUtils.isNotBlank(folderName)) {
                s3Object.setKey(folderName + "/" + fileName);
            } else {
                s3Object.setKey(fileName);
            }
            s3Object.setContentType(mimeType);
            s3Object.setContentLength(file.length());
            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);
        } 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 , String mimeType , Map < String , Object > metaData , File file , String bucketName , String folderName ) throws FileTransferException { if ( StringUtils . isEmpty ( bucketName ) ) { throw new FileTransferException ( "No bucket name was supplied." ) ; } try { S3Object s3Object = new S3Object ( file ) ; if ( StringUtils . isNotBlank ( folderName ) ) { s3Object . setKey ( folderName + "/" + fileName ) ; } else { s3Object . setKey ( fileName ) ; } s3Object . setContentType ( mimeType ) ; s3Object . setContentLength ( file . length ( ) ) ; 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 ) ; } 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 to the supplied bucketName and sets the files content type in S3.
Uploads a File to the supplied bucketName and sets the files content type in S3 .