开发者

Android Abort Uploading Amazon S3 Bucket

D开发者_开发技巧o anyone know that how to Abort File Uploading for an Amazon S3 Bucket. i'm using following code to Upload a file.

transferManager = new TransferManager(amazonClient);
upload = transferManager.upload(BUCKET_NAME, FILE_NAME, file);
try {

upload.addProgressListener(listner);    
upload.waitForUploadResult();
AppLog.logString("Unable to upload file, upload was aborted");                         

} 
catch (AmazonClientException amazonClientException) {
        System.out.println("Unable to upload file, upload was aborted.");
        amazonClientException.printStackTrace();
} 


This is roughly how I do it. You will need to adapt it for your scenario, of course.

    PutObjectRequest request = new PutObjectRequest(bucket, key, file);

    request.setProgressListener(new ProgressListener() {
        public void progressChanged(ProgressEvent progressEvent) {
             if (aborted.get()) {
                throw new RuntimeException("Aborted");
            }
        }
    });

    try {
        PutObjectResult result = s3.putObject(request);
    } catch (AmazonClientException e) {
       // Handle exception 
    }

Set aborted to true to stop upload. You will need to recognize your exception in catch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜