List of usage examples for com.amazonaws.services.s3.model UploadPartRequest withSSECustomerKey
public UploadPartRequest withSSECustomerKey(SSECustomerKey sseKey)
From source file:io.minio.awssdk.tests.S3TestUtils.java
License:Apache License
void uploadMultipartObject(String bucketName, String keyName, String filePath, SSECustomerKey sseKey) throws IOException { File file = new File(filePath); List<PartETag> partETags = new ArrayList<PartETag>(); // Step 1: Initialize. InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucketName, keyName); if (sseKey != null) { initRequest.setSSECustomerKey(sseKey); }/*w ww. ja va 2 s .c om*/ InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest); long contentLength = file.length(); long partSize = 5242880; // Set part size to 5 MB. // Step 2: Upload parts. long filePosition = 0; for (int i = 1; filePosition < contentLength; i++) { // Last part can be less than 5 MB. Adjust part size. partSize = Math.min(partSize, (contentLength - filePosition)); // Create request to upload a part. UploadPartRequest uploadRequest = new UploadPartRequest().withBucketName(bucketName).withKey(keyName) .withUploadId(initResponse.getUploadId()).withPartNumber(i).withFileOffset(filePosition) .withFile(file).withPartSize(partSize); if (sseKey != null) { uploadRequest.withSSECustomerKey(sseKey); } // Upload part and add response to our list. partETags.add(s3Client.uploadPart(uploadRequest).getPartETag()); filePosition += partSize; } // Step 3: Complete. CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucketName, keyName, initResponse.getUploadId(), partETags); s3Client.completeMultipartUpload(compRequest); }