fix(stream): http chucked upload issue (#1152)

* fix(stream): http chucked upload issue

* fix(stream): use MmapThreshold

* fix(stream): improve caching mechanism and handle size=0 case

* fix bug

* fix(buffer): optimize ReadAt method for improved performance

* fix(upload): handle Content-Length and File-Size headers for better size management

* fix(189pc): 移除重复限速

* fix(upload): handle negative file size during streaming uploads

* fix(upload): update header key from File-Size to X-File-Size for size retrieval

---------

Co-authored-by: j2rong4cn <j2rong@qq.com>
This commit is contained in:
TwoOnefour
2025-09-15 19:36:16 +08:00
committed by GitHub
parent c1d03c5bcc
commit cbbb5ad231
8 changed files with 207 additions and 45 deletions

View File

@@ -56,14 +56,17 @@ func FsStream(c *gin.Context) {
}
}
dir, name := stdpath.Split(path)
sizeStr := c.GetHeader("Content-Length")
if sizeStr == "" {
sizeStr = "0"
}
size, err := strconv.ParseInt(sizeStr, 10, 64)
if err != nil {
common.ErrorResp(c, err, 400)
return
// 如果请求头 Content-Length 和 X-File-Size 都没有,则 size=-1表示未知大小的流式上传
size := c.Request.ContentLength
if size < 0 {
sizeStr := c.GetHeader("X-File-Size")
if sizeStr != "" {
size, err = strconv.ParseInt(sizeStr, 10, 64)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
}
}
h := make(map[*utils.HashType]string)
if md5 := c.GetHeader("X-File-Md5"); md5 != "" {

View File

@@ -14,6 +14,7 @@ import (
"net/url"
"os"
"path"
"strconv"
"strings"
"time"
@@ -341,9 +342,19 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
if err != nil {
return http.StatusForbidden, err
}
size := r.ContentLength
if size < 0 {
sizeStr := r.Header.Get("X-File-Size")
if sizeStr != "" {
size, err = strconv.ParseInt(sizeStr, 10, 64)
if err != nil {
return http.StatusBadRequest, err
}
}
}
obj := model.Object{
Name: path.Base(reqPath),
Size: r.ContentLength,
Size: size,
Modified: h.getModTime(r),
Ctime: h.getCreateTime(r),
}