From 0f29a811bfa608cd99642c083538852ed7f923d1 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Fri, 19 Jan 2024 12:05:10 +0800 Subject: [PATCH] fix: s3 upload exceeded total allowed configured MaxUploadParts (close #5909) --- drivers/123/driver.go | 10 +++++++--- drivers/mediatrack/driver.go | 3 +++ drivers/pikpak/driver.go | 3 +++ drivers/quqi/driver.go | 2 +- drivers/teambition/util.go | 3 +++ drivers/thunder/driver.go | 6 +++++- drivers/vtencent/util.go | 3 +++ 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/123/driver.go b/drivers/123/driver.go index 6f7fec1bd43..1f1ae85886a 100644 --- a/drivers/123/driver.go +++ b/drivers/123/driver.go @@ -6,6 +6,10 @@ import ( "encoding/base64" "encoding/hex" "fmt" + "io" + "net/http" + "net/url" + "github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/errs" @@ -17,9 +21,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/go-resty/resty/v2" log "github.com/sirupsen/logrus" - "io" - "net/http" - "net/url" ) type Pan123 struct { @@ -232,6 +233,9 @@ func (d *Pan123) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr return err } uploader := s3manager.NewUploader(s) + if stream.GetSize() > s3manager.MaxUploadParts*s3manager.DefaultUploadPartSize { + uploader.PartSize = stream.GetSize() / (s3manager.MaxUploadParts - 1) + } input := &s3manager.UploadInput{ Bucket: &resp.Data.Bucket, Key: &resp.Data.Key, diff --git a/drivers/mediatrack/driver.go b/drivers/mediatrack/driver.go index 90e66ae0e34..ef571832eb7 100644 --- a/drivers/mediatrack/driver.go +++ b/drivers/mediatrack/driver.go @@ -188,6 +188,9 @@ func (d *MediaTrack) Put(ctx context.Context, dstDir model.Obj, stream model.Fil _ = tempFile.Close() }() uploader := s3manager.NewUploader(s) + if stream.GetSize() > s3manager.MaxUploadParts*s3manager.DefaultUploadPartSize { + uploader.PartSize = stream.GetSize() / (s3manager.MaxUploadParts - 1) + } input := &s3manager.UploadInput{ Bucket: &resp.Data.Bucket, Key: &resp.Data.Object, diff --git a/drivers/pikpak/driver.go b/drivers/pikpak/driver.go index 52ca15c798a..f3676b8291b 100644 --- a/drivers/pikpak/driver.go +++ b/drivers/pikpak/driver.go @@ -172,6 +172,9 @@ func (d *PikPak) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr return err } uploader := s3manager.NewUploader(ss) + if stream.GetSize() > s3manager.MaxUploadParts*s3manager.DefaultUploadPartSize { + uploader.PartSize = stream.GetSize() / (s3manager.MaxUploadParts - 1) + } input := &s3manager.UploadInput{ Bucket: ¶ms.Bucket, Key: ¶ms.Key, diff --git a/drivers/quqi/driver.go b/drivers/quqi/driver.go index 0a3d347aa04..508c8b6b32e 100644 --- a/drivers/quqi/driver.go +++ b/drivers/quqi/driver.go @@ -311,7 +311,7 @@ func (d *Quqi) Put(ctx context.Context, dstDir model.Obj, stream model.FileStrea length = stream.GetSize() - (int64(i)-1)*partSize } _, err := client.Object.UploadPart( - context.Background(), uploadInitResp.Data.Key, uploadInitResp.Data.UploadID, i, io.LimitReader(f, partSize), &cos.ObjectUploadPartOptions{ + ctx, uploadInitResp.Data.Key, uploadInitResp.Data.UploadID, i, io.LimitReader(f, partSize), &cos.ObjectUploadPartOptions{ ContentLength: length, }, ) diff --git a/drivers/teambition/util.go b/drivers/teambition/util.go index 79de7007c78..181cc58f64c 100644 --- a/drivers/teambition/util.go +++ b/drivers/teambition/util.go @@ -244,6 +244,9 @@ func (d *Teambition) newUpload(ctx context.Context, dstDir model.Obj, stream mod return err } uploader := s3manager.NewUploader(ss) + if stream.GetSize() > s3manager.MaxUploadParts*s3manager.DefaultUploadPartSize { + uploader.PartSize = stream.GetSize() / (s3manager.MaxUploadParts - 1) + } input := &s3manager.UploadInput{ Bucket: &uploadToken.Upload.Bucket, Key: &uploadToken.Upload.Key, diff --git a/drivers/thunder/driver.go b/drivers/thunder/driver.go index cac6733f01b..9ba5dd825f7 100644 --- a/drivers/thunder/driver.go +++ b/drivers/thunder/driver.go @@ -373,7 +373,11 @@ func (xc *XunLeiCommon) Put(ctx context.Context, dstDir model.Obj, stream model. if err != nil { return err } - _, err = s3manager.NewUploader(s).UploadWithContext(ctx, &s3manager.UploadInput{ + uploader := s3manager.NewUploader(s) + if stream.GetSize() > s3manager.MaxUploadParts*s3manager.DefaultUploadPartSize { + uploader.PartSize = stream.GetSize() / (s3manager.MaxUploadParts - 1) + } + _, err = uploader.UploadWithContext(ctx, &s3manager.UploadInput{ Bucket: aws.String(param.Bucket), Key: aws.String(param.Key), Expires: aws.Time(param.Expiration), diff --git a/drivers/vtencent/util.go b/drivers/vtencent/util.go index bf260415e0c..ba87f1abe51 100644 --- a/drivers/vtencent/util.go +++ b/drivers/vtencent/util.go @@ -272,6 +272,9 @@ func (d *Vtencent) FileUpload(ctx context.Context, dstDir model.Obj, stream mode return err } uploader := s3manager.NewUploader(ss) + if stream.GetSize() > s3manager.MaxUploadParts*s3manager.DefaultUploadPartSize { + uploader.PartSize = stream.GetSize() / (s3manager.MaxUploadParts - 1) + } input := &s3manager.UploadInput{ Bucket: aws.String(fmt.Sprintf("%s-%d", params.StorageBucket, params.StorageAppID)), Key: ¶ms.Video.StoragePath,