有谁知道如何为Amazon S3 Bucket中止文件上传。 我正在使用以下代码上传文件。
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();
}
答案 0 :(得分:2)
这大致是我的表现。当然,您需要根据自己的情况进行调整。
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
}
将aborted
设置为true以停止上传。您需要在catch
中识别您的例外情况。