从亚马逊s3下载文件

时间:2017-10-31 05:49:04

标签: java amazon-s3

嗨,大家好我在像亚马逊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();

0 个答案:

没有答案