部件成功完成后,S3多部件上载在完成后失败

时间:2018-03-05 02:32:44

标签: java amazon-s3

我试图将从内存中生成的数据上传到S3。

以下是实际上传部分的代码:

UploadPartRequest partReq = new UploadPartRequest()
    .withBucketName( this.getBucket() )
    .withKey( this.getKey() )
    .withUploadId( uploadId )
    .withPartNumber( partNumber )
    .withPartSize( partSize )
    .withInputStream( is )
    .withGeneralProgressListener( (ProgressEvent e) -> {
            log.info( "{} {} {} {} {} {} bytes transferred",
            this.getBucket(), this.getKey(), uploadId, partNumber,
            e.getEventType(), e.getBytesTransferred() );
    });
UploadPartResult partRes = this.getClient().uploadPart( partReq );

上传所有部件之后,我的日志中出现了以下行,我认为这些部分都已成功上传。

1 TRANSFER_PART_COMPLETED_EVENT 
2 TRANSFER_PART_COMPLETED_EVENT 
3 TRANSFER_PART_COMPLETED_EVENT 
4 TRANSFER_PART_COMPLETED_EVENT 
5 TRANSFER_PART_COMPLETED_EVENT 
6 TRANSFER_PART_COMPLETED_EVENT 
7 TRANSFER_PART_COMPLETED_EVENT 
8 TRANSFER_PART_COMPLETED_EVENT 
9 TRANSFER_PART_COMPLETED_EVENT 
10 TRANSFER_PART_COMPLETED_EVENT
11 TRANSFER_PART_COMPLETED_EVENT
12 TRANSFER_PART_COMPLETED_EVENT
13 TRANSFER_PART_COMPLETED_EVENT
14 TRANSFER_PART_COMPLETED_EVENT
15 TRANSFER_PART_COMPLETED_EVENT
17 TRANSFER_PART_COMPLETED_EVENT
16 TRANSFER_PART_COMPLETED_EVENT

对于每个上传部分,当他们仍在上传时,也会出现以下这一行,这告诉我确实是在为这些上传发送数据。

REQUEST_BYTE_TRANSFER_EVENT 8192 bytes transferred

以下是我用来最终完成整个上传过程的代码。

CompleteMultipartUploadRequest cmpur = new CompleteMultipartUploadRequest()
    .withBucketName( this.getBucket() )
    .withKey( this.getKey() )
    .withUploadId( result.getUploadId() )
    .withPartETags( new ArrayList<>( this.getUploadPartResults() ) )
    .withGeneralProgressListener((e) -> {
        log.info( "{} {} {} {} bytes transferred",
        this.getBucket(), this.getKey(),
        e.getEventType(), e.getBytesTransferred() );
    });
this.getClient().completeMultipartUpload( cmpur );

在发送完成整个多部分上传的请求后,我在日志中收到以下内容:

REQUEST_CONTENT_LENGTH_EVENT
CLIENT_REQUEST_STARTED_EVENT
HTTP_REQUEST_STARTED_EVENT
HTTP_REQUEST_COMPLETED_EVENT
CLIENT_REQUEST_FAILED_EVENT

然后线程挂在那里。

我认为CLIENT_REQUEST_FAILED_EVENT表示整个上传失败。我错过了什么?

我尝试增加零件尺寸,因此整个多部件上传只有一个上传部件,并且成功了。如果总零件数超过1则失败。

这里有成功上传的日志,因为它只有一个部分。

REQUEST_CONTENT_LENGTH_EVENT 0 bytes transferred
CLIENT_REQUEST_STARTED_EVENT 0 bytes transferred
HTTP_REQUEST_STARTED_EVENT 0 bytes transferred
HTTP_REQUEST_COMPLETED_EVENT 0 bytes transferred
RESPONSE_CONTENT_LENGTH_EVENT 0 bytes transferred
HTTP_RESPONSE_STARTED_EVENT 0 bytes transferred
RESPONSE_BYTE_TRANSFER_EVENT 309 bytes transferred
HTTP_RESPONSE_COMPLETED_EVENT 0 bytes transferred
CLIENT_REQUEST_SUCCESS_EVENT 0 bytes transferred
REQUEST_BYTE_TRANSFER_EVENT 135 bytes transferred

也许,我还可以在日志中添加更多内容以查看出现了什么问题?

1 个答案:

答案 0 :(得分:0)

我发现这是因为我的部件实际上小于所需的最小尺寸5MB。

https://docs.aws.amazon.com/AmazonS3/latest/dev/qfacts.html

我几次去过那个页面,但我忽略了它。这很容易被忽视。日志也没有帮助。