publicbooleanmultipartUploadWithS3Client(StringaccessKey,StringsecretKey,Stringregion,StringbucketName,Stringkey,StringfilePath){log.info("for file {}, upload starting for bucket {}, to s3 location {} ",filePath,bucketName,key);StopWatchwatch=newStopWatch();watch.start();// S3 ClientS3Clients3Client=getAWSS3Client(accessKey,secretKey,region);// Initiate the multipart upload.CreateMultipartUploadResponsecreateMultipartUploadResponse=s3Client.createMultipartUpload(b->b.bucket(bucketName).key(key));// get the upload idStringuploadId=createMultipartUploadResponse.uploadId();log.info("Upload ID: {}",uploadId);// Upload the parts of the file.intpartNumber=1;List<CompletedPart>completedParts=newArrayList<>();ByteBufferbb=ByteBuffer.allocate(1024*1024*10);// 10 MB byte buffer// Read the file and upload the parts.try(RandomAccessFilefile=newRandomAccessFile(filePath,"r")){longfileSize=file.length();longposition=0;while(position<fileSize){file.seek(position);intread=file.getChannel().read(bb);bb.flip();// Swap position and limit before reading from the buffer.UploadPartRequestuploadPartRequest=UploadPartRequest.builder().bucket(bucketName).key(key).uploadId(uploadId).partNumber(partNumber).build();UploadPartResponsepartResponse=s3Client.uploadPart(uploadPartRequest,RequestBody.fromByteBuffer(bb));CompletedPartpart=CompletedPart.builder().partNumber(partNumber).eTag(partResponse.eTag()).build();completedParts.add(part);bb.clear();position+=read;partNumber++;}}catch(IOExceptione){log.error("Error while uploading file to s3",e);returnfalse;}log.info("Completed parts: {}",completedParts.size());// Complete the multipart upload.s3Client.completeMultipartUpload(b->b.bucket(bucketName).key(key).uploadId(uploadId).multipartUpload(CompletedMultipartUpload.builder().parts(completedParts).build()));watch.stop();StringtimeTakenInHMSFormat=DateTimeFormatter.ofPattern("HH:mm:ss.SSS").withZone(ZoneId.of("UTC")).format(Instant.ofEpochMilli(watch.getTotalTimeMillis()));log.info("Time taken to upload file {} to s3 bucket {}for this location {} is: {}",filePath,bucketName,key,timeTakenInHMSFormat);returntrue;}