feat: add support for resuming an existing upload
This commit is contained in:
parent
3ded11d705
commit
f73ad52864
|
@ -151,16 +151,46 @@ func (r *RenterDefault) UploadObjectMultipart(ctx context.Context, params *Multi
|
||||||
parts := uint64(math.Ceil(float64(size) / float64(slabSize)))
|
parts := uint64(math.Ceil(float64(size) / float64(slabSize)))
|
||||||
uploadParts := make([]api.MultipartCompletedPart, parts)
|
uploadParts := make([]api.MultipartCompletedPart, parts)
|
||||||
|
|
||||||
|
var uploadId string
|
||||||
|
start := uint64(0)
|
||||||
|
|
||||||
|
if params.ExistingUploadID != "" {
|
||||||
|
existing, err := r.busClient.MultipartUploadParts(ctx, bucket, fileName, params.ExistingUploadID, 0, 0)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadId = params.ExistingUploadID
|
||||||
|
|
||||||
|
for _, part := range existing.Parts {
|
||||||
|
if uint64(part.Size) != slabSize {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
partNumber := part.PartNumber
|
||||||
|
uploadParts[partNumber-1] = api.MultipartCompletedPart{
|
||||||
|
PartNumber: part.PartNumber,
|
||||||
|
ETag: part.ETag,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(uploadParts) > 0 {
|
||||||
|
start = uint64(len(uploadParts)) - 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
upload, err := r.busClient.CreateMultipartUpload(ctx, bucket, fileName, api.CreateMultipartOptions{Key: object.NoOpKey})
|
upload, err := r.busClient.CreateMultipartUpload(ctx, bucket, fileName, api.CreateMultipartOptions{Key: object.NoOpKey})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if idHandler != nil {
|
uploadId = upload.UploadID
|
||||||
idHandler(upload.UploadID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := uint64(0); i < parts; i++ {
|
if idHandler != nil {
|
||||||
|
idHandler(uploadId)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := start; i < parts; i++ {
|
||||||
start := i * slabSize
|
start := i * slabSize
|
||||||
|
|
||||||
end := start + slabSize
|
end := start + slabSize
|
||||||
|
@ -187,7 +217,7 @@ func (r *RenterDefault) UploadObjectMultipart(ctx context.Context, params *Multi
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := r.workerClient.UploadMultipartUploadPart(context.Background(), reader, bucket, fileName, upload.UploadID, partNumber, api.UploadMultipartUploadPartOptions{})
|
ret, err := r.workerClient.UploadMultipartUploadPart(context.Background(), reader, bucket, fileName, uploadId, partNumber, api.UploadMultipartUploadPartOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -219,11 +249,13 @@ func (r *RenterDefault) UploadObjectMultipart(ctx context.Context, params *Multi
|
||||||
return fmt.Errorf("failed to upload part %d: %s", i, err.Error())
|
return fmt.Errorf("failed to upload part %d: %s", i, err.Error())
|
||||||
case etag := <-nextChan:
|
case etag := <-nextChan:
|
||||||
uploadParts[i].ETag = etag
|
uploadParts[i].ETag = etag
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = r.busClient.CompleteMultipartUpload(ctx, bucket, fileName, upload.UploadID, uploadParts)
|
_, err = r.busClient.CompleteMultipartUpload(ctx, bucket, fileName, uploadId, uploadParts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue