我正在将多部分文件上传到S3。我添加了一个ProgressListener来打印进度,效果很好。太棒了。我上传的文件有几GB大,而且我记录的消息太细了。我收到了几千个这样的:
2021-11-04 06:56:07 INFO GenericSftpLoader:190 - transfered bytes: 8192
有没有什么方法可以减少这种情况,从每8192个字节打印一次,改为更合理的1048576个字节?
我的实际代码是在Scala中编写的,但我密切关注AWS SDK文档中的这个例子:
TransferManager tm = new TransferManager(new ProfileCredentialsProvider());
PutObjectRequest request = new PutObjectRequest(
existingBucketName, keyName, new File(filePath));
request.setGeneralProgressListener(new ProgressListener() {
@Override
public void progressChanged(ProgressEvent progressEvent) {
System.out.println("Transferred bytes: " +
progressEvent.getBytesTransferred());
}
});
Upload upload = tm.upload(request);
所以我得到了一个解决方案。以下是我所做的:
TransferManager tm=新的TransferManager(new ProfileCredentialsProvider(((;
PutObjectRequest request = new PutObjectRequest(
existingBucketName, keyName, new File(filePath));
request.setGeneralProgressListener(new ProgressListener() {
private Long myBytes = 0
@Override
public void progressChanged(ProgressEvent progressEvent) {
myBytes += progressEvent.getBytesTransferred();
if (bytesTransferred > 1048576) {
System.out.println("Transferred bytes: " +
myBytes);
myBytes = 0;
}
}
});
Upload upload = tm.upload(request);