putObject在AmazonS3Client阻塞吗?

时间:2016-11-29 12:21:55

标签: amazon-s3 aws-sdk

你知道方法 -

吗?
public PutObjectResult putObject(PutObjectRequest putObjectRequest)

AmazonS3Client阻止?

1 个答案:

答案 0 :(得分:4)

是的,它是阻止的,它会返回一个结果。如果您想进行更复杂的上传,请查看:

DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
TransferManager tx = new TransferManager(
           credentialProviderChain.getCredentials());
Upload myUpload = tx.upload(myBucket, myFile.getName(), myFile);

// You can poll your transfer's status to check its progress
if (myUpload.isDone() == false) {
   System.out.println("Transfer: " + myUpload.getDescription());
   System.out.println("  - State: " + myUpload.getState());
   System.out.println("  - Progress: "
                   + myUpload.getProgress().getBytesTransferred());
}

// Transfers also allow you to set a <code>ProgressListener</code> to receive
// asynchronous notifications about your transfer's progress.
myUpload.addProgressListener(myProgressListener);

// Or you can block the current thread and wait for your transfer to
// to complete. If the transfer fails, this method will throw an
// AmazonClientException or AmazonServiceException detailing the reason.
myUpload.waitForCompletion();

// After the upload is complete, call shutdownNow to release the resources.
tx.shutdownNow();

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferManager.html