- Introduce a file size restriction to handle uploads more securely. - Provide an informative error for uploads that exceed the new limit.
This commit is contained in:
parent
a701432b8b
commit
216e3909f3
@ -2,6 +2,7 @@ package _115
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -121,7 +122,10 @@ func (d *Pan115) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
|
|||||||
if err := d.WaitLimit(ctx); err != nil {
|
if err := d.WaitLimit(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if stream.GetSize() > utils.GB*20 { // TODO 由于官方分片上传接口失效,所以使用普通上传小于20GB的文件
|
||||||
|
return fmt.Errorf("unsupported file size: 20GB limit exceeded")
|
||||||
|
}
|
||||||
|
// 分片上传
|
||||||
var (
|
var (
|
||||||
fastInfo *driver115.UploadInitResp
|
fastInfo *driver115.UploadInitResp
|
||||||
dirID = dstDir.GetID()
|
dirID = dstDir.GetID()
|
||||||
@ -177,11 +181,13 @@ func (d *Pan115) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 闪传失败,上传
|
// 闪传失败,上传
|
||||||
if stream.GetSize() <= utils.KB { // 文件大小小于1KB,改用普通模式上传
|
// if stream.GetSize() <= utils.KB{ // 文件大小小于1KB,改用普通模式上传
|
||||||
|
if stream.GetSize() <= utils.GB*20 { // TODO 由于官方分片上传接口失效,所以使用普通上传小于20GB的文件
|
||||||
return d.client.UploadByOSS(&fastInfo.UploadOSSParams, stream, dirID)
|
return d.client.UploadByOSS(&fastInfo.UploadOSSParams, stream, dirID)
|
||||||
}
|
}
|
||||||
|
return driver115.ErrUnexpected
|
||||||
// 分片上传
|
// 分片上传
|
||||||
return d.UploadByMultipart(&fastInfo.UploadOSSParams, stream.GetSize(), stream, dirID)
|
// return d.UploadByMultipart(&fastInfo.UploadOSSParams, stream.GetSize(), stream, dirID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Pan115) OfflineList(ctx context.Context) ([]*driver115.OfflineTask, error) {
|
func (d *Pan115) OfflineList(ctx context.Context) ([]*driver115.OfflineTask, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user