可靠性: 完善 R2 备份恢复与对象生命周期
This commit is contained in:
@@ -871,7 +871,7 @@ func uploadImage(ctx context.Context, opts uploadImageOptions) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get S3 client")
|
||||
}
|
||||
if _, err := client.PutObject(ctx.Request().Context(), &s3.PutObjectInput{
|
||||
if err := storage.PutObject(ctx.Request().Context(), client, &s3.PutObjectInput{
|
||||
Bucket: aws.String(conf.Upload.ImageBucket),
|
||||
Key: aws.String(uploadKey),
|
||||
Body: bytes.NewReader(uploadData),
|
||||
@@ -894,6 +894,9 @@ func uploadImage(ctx context.Context, opts uploadImageOptions) error {
|
||||
IsDeletingPrevious: opts.IsDeletingPrevious,
|
||||
})
|
||||
if err != nil {
|
||||
if enqueueErr := db.R2DeleteTasks.Enqueue(ctx.Request().Context(), conf.Upload.ImageBucket, []string{uploadKey}); enqueueErr != nil {
|
||||
return errors.Wrapf(enqueueErr, "compensate upload image after metadata failure: %v", err)
|
||||
}
|
||||
return errors.Wrap(err, "create upload image")
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user