Skip to content

Commit 0fea41b

Browse files
committed
fix(upload): handle negative file size during streaming uploads
1 parent a9f5cef commit 0fea41b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

internal/op/fs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file mod
630630
up = func(p float64) {}
631631
}
632632

633+
// 如果小于0,则通过缓存获取完整大小,可能发生于流式上传
634+
if file.GetSize() < 0 {
635+
log.Warnf("file size < 0, try to get full size from cache")
636+
file.CacheFullAndWriter(nil, nil)
637+
}
633638
switch s := storage.(type) {
634639
case driver.PutResult:
635640
var newObj model.Obj

server/handles/fsup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func FsStream(c *gin.Context) {
5656
}
5757
}
5858
dir, name := stdpath.Split(path)
59+
// 如果请求头 Content-Length 和 File-Size 都没有,则 size=-1,表示未知大小的流式上传
5960
size := c.Request.ContentLength
6061
if size < 0 {
6162
sizeStr := c.GetHeader("File-Size")

0 commit comments

Comments
 (0)