fix: if for some edge case reason an upload id no longer exists, start over, but use db Save so we can update the record if we have an ID
This commit is contained in:
parent
56100e5d50
commit
b46e12b972
|
@ -370,6 +370,30 @@ func (s StorageServiceDefault) S3MultipartUpload(ctx context.Context, data io.Re
|
||||||
uploadId = s3Upload.UploadID
|
uploadId = s3Upload.UploadID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(uploadId) > 0 {
|
||||||
|
parts, err := client.ListParts(ctx, &s3.ListPartsInput{
|
||||||
|
Bucket: aws.String(bucket),
|
||||||
|
Key: aws.String(key),
|
||||||
|
UploadId: aws.String(uploadId),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
uploadId = ""
|
||||||
|
} else {
|
||||||
|
for _, part := range parts.Parts {
|
||||||
|
if uint64(*part.Size) == partSize {
|
||||||
|
if *part.PartNumber > lastPartNumber {
|
||||||
|
lastPartNumber = *part.PartNumber
|
||||||
|
completedParts = append(completedParts, types.CompletedPart{
|
||||||
|
ETag: part.ETag,
|
||||||
|
PartNumber: part.PartNumber,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if uploadId == "" {
|
if uploadId == "" {
|
||||||
mu, err := client.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{
|
mu, err := client.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
|
@ -382,32 +406,10 @@ func (s StorageServiceDefault) S3MultipartUpload(ctx context.Context, data io.Re
|
||||||
uploadId = *mu.UploadId
|
uploadId = *mu.UploadId
|
||||||
|
|
||||||
s3Upload.UploadID = uploadId
|
s3Upload.UploadID = uploadId
|
||||||
ret = s.db.Create(&s3Upload)
|
ret = s.db.Save(&s3Upload)
|
||||||
if ret.Error != nil {
|
if ret.Error != nil {
|
||||||
return ret.Error
|
return ret.Error
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
parts, err := client.ListParts(ctx, &s3.ListPartsInput{
|
|
||||||
Bucket: aws.String(bucket),
|
|
||||||
Key: aws.String(key),
|
|
||||||
UploadId: aws.String(uploadId),
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, part := range parts.Parts {
|
|
||||||
if uint64(*part.Size) == partSize {
|
|
||||||
if *part.PartNumber > lastPartNumber {
|
|
||||||
lastPartNumber = *part.PartNumber
|
|
||||||
completedParts = append(completedParts, types.CompletedPart{
|
|
||||||
ETag: part.ETag,
|
|
||||||
PartNumber: part.PartNumber,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for partNum := 1; partNum <= totalParts; partNum++ {
|
for partNum := 1; partNum <= totalParts; partNum++ {
|
||||||
|
|
Loading…
Reference in New Issue