Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 SdkClientException while Directory Uploading in Java

I am using this code for uploading directory on S3.

TransferManager transferManager = new TransferManager(s3client);
MultipleFileUpload uploaded = transferManager.uploadDirectory(BUCKET_NAME, "DirectoryName", new File(uploadDirectory), true);

While uploading Directory to Amazon S3 bucket I get the following exception

com.amazonaws.SdkClientException: Upload canceled
    at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:159)
    at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:47)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

This exception generally occur around 10 times in 100 attempt

Note- The above code is executing in Multithreaded environment with the same s3client object

Thanks a lot!

like image 363
Ankit Singh Avatar asked Oct 04 '17 11:10

Ankit Singh


Video Answer


1 Answers

The Solution of above problem i encountered while doing R&D in Java Amazon Sdk. Instead of creating different TransferManager instances for every thread share the same instances with multiple threads if you are using same AmazonS3Client.

It will not cause any issue because it is thread safe object and problem was also solved.

like image 157
Ankit Singh Avatar answered Nov 15 '22 00:11

Ankit Singh