嗨,大家好我在像亚马逊s3下载文件这样的项目下工作。我的文件被大块成功下载[即下载5×5 MB或更多]。但是我的下载文件在完成后已损坏。
GetObjectRequest rangeObjectRequest = new getObjectRequest(existingBucketName, fileName);
long filePosition = 0;
int part = 0;
while (filePosition < contentLength)
{
blockSize = Math.min(blockSize, (contentLength - filePosition));
Thread.currentThread();
if( Thread.interrupted() )
{
throw new InterruptedException();
}
rangeObjectRequest.setRange(filePosition, filePosition + blockSize);
S3Object objectPortion = s3Client.getObject(rangeObjectRequest);
InputStream objectData = objectPortion.getObjectContent();
IOUtils.copy(objectData, out);
filePosition = filePosition + blockSize;
part++;
}
out.close();
objectContent.close();