4343import java .util .ArrayList ;
4444import java .util .List ;
4545
46+ import static com .amazonaws .services .s3 .internal .Constants .GB ;
4647import static com .amazonaws .services .s3 .internal .Constants .MAXIMUM_UPLOAD_PARTS ;
4748import static com .amazonaws .services .s3 .internal .Constants .MB ;
4849
@@ -141,7 +142,9 @@ public class TransferUtility {
141142 * Default minimum part size for upload parts. Anything below this will use a
142143 * single upload
143144 */
144- static final int MINIMUM_UPLOAD_PART_SIZE = 5 * MB ;
145+ static final int DEFAULT_MINIMUM_UPLOAD_PART_SIZE_IN_BYTES = 5 * MB ;
146+ static final int MINIMUM_SUPPORTED_UPLOAD_PART_SIZE_IN_BYTES = 5 * MB ;
147+ static final long MAXIMUM_SUPPORTED_UPLOAD_PART_SIZE_IN_BYTES = 5 * GB ;
145148
146149 private static String userAgentFromConfig = "" ;
147150
@@ -770,15 +773,16 @@ private List<Integer> getTransferIdsWithTypeAndStates(TransferType type, Transfe
770773 */
771774 private int createMultipartUploadRecords (String bucket , String key , File file , ObjectMetadata metadata ,
772775 CannedAccessControlList cannedAcl ) {
773- long remainingLenth = file .length ();
774- double partSize = (double ) remainingLenth / (double ) MAXIMUM_UPLOAD_PARTS ;
776+ long remainingLength = file .length ();
777+ double partSize = (double ) remainingLength / (double ) MAXIMUM_UPLOAD_PARTS ;
775778 partSize = Math .ceil (partSize );
776- final long optimalPartSize = (long ) Math .max (partSize , MINIMUM_UPLOAD_PART_SIZE );
779+ final long optimalPartSize = (long ) Math .max (partSize ,
780+ transferUtilityOptions .getMinimumUploadPartSizeInBytes ());
777781 long fileOffset = 0 ;
778782 int partNumber = 1 ;
779783
780784 // the number of parts
781- final int partCount = (int ) Math .ceil ((double ) remainingLenth / (double ) optimalPartSize );
785+ final int partCount = (int ) Math .ceil ((double ) remainingLength / (double ) optimalPartSize );
782786
783787 /*
784788 * the size of valuesArray is partCount + 1, one for a multipart upload summary,
@@ -788,11 +792,11 @@ private int createMultipartUploadRecords(String bucket, String key, File file, O
788792 valuesArray [0 ] = dbUtil .generateContentValuesForMultiPartUpload (bucket , key , file , fileOffset , 0 , "" ,
789793 file .length (), 0 , metadata , cannedAcl , transferUtilityOptions );
790794 for (int i = 1 ; i < partCount + 1 ; i ++) {
791- final long bytesForPart = Math .min (optimalPartSize , remainingLenth );
795+ final long bytesForPart = Math .min (optimalPartSize , remainingLength );
792796 valuesArray [i ] = dbUtil .generateContentValuesForMultiPartUpload (bucket , key , file , fileOffset , partNumber ,
793- "" , bytesForPart , remainingLenth - optimalPartSize <= 0 ? 1 : 0 , metadata , cannedAcl , transferUtilityOptions );
797+ "" , bytesForPart , remainingLength - optimalPartSize <= 0 ? 1 : 0 , metadata , cannedAcl , transferUtilityOptions );
794798 fileOffset += optimalPartSize ;
795- remainingLenth -= optimalPartSize ;
799+ remainingLength -= optimalPartSize ;
796800 partNumber ++;
797801 }
798802 return dbUtil .bulkInsertTransferRecords (valuesArray );
@@ -986,7 +990,10 @@ private synchronized void submitTransferJob(String action, int id) {
986990 }
987991
988992 private boolean shouldUploadInMultipart (File file ) {
989- return (file != null && file .length () > MINIMUM_UPLOAD_PART_SIZE );
993+ return (
994+ file != null &&
995+ file .length () > transferUtilityOptions .getMinimumUploadPartSizeInBytes ()
996+ );
990997 }
991998
992999 static <X extends AmazonWebServiceRequest > X appendTransferServiceUserAgentString (final X request ) {
0 commit comments