gpt4 book ai didi

java - Amazon S3 AWS 上传进度监听器

转载 作者:行者123 更新时间:2023-11-29 08:27:02 24 4
gpt4 key购买 nike

有谁知道如何在 Amazon S3 中查看分段上传中的上传进度(百分比)?

最佳答案

我会这样做:

MultipleFileUpload transfer = transferManager.uploadDirectory(mybucket, null, new File(localSourceDataFilesPath), false);

// blocks the thread until the upload is completed
showTransferProgress(transfer);

然后在 showTransferProgress 中,我将创建一个使用 hibernate 的上传 block ,并每隔 X 秒计算一次:

private void showTransferProgress(MultipleFileUpload xfer) {
while (!xfer.isDone()) {
// some logic to wait so you don't do the math every second like a Thread.sleep

TransferProgress progress = xfer.getProgress();
long bytesTransferred = progress.getBytesTransferred();
long total = progress.getTotalBytesToTransfer();
Double percentDone = progress.getPercentTransferred();
LOG.debug("S3 xml upload progress...{}%", percentDone.intValue());
LOG.debug("{} bytes transferred to S3 out of {}", bytesTransferred, total);
}

// print the final state of the transfer.
TransferState xferState = xfer.getState();
LOG.debug("Final transfer state: " + xferState);
}

这一行就是你要找的:

Double percentDone = progress.getPercentTransferred();

关于java - Amazon S3 AWS 上传进度监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51873760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com