Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed May 14, 2023
1 parent 636134b commit c98e247
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions upload/base_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (a *BaseClient) Upload(opts ...OptionsSetter) Client {
FileName: options.Result.FileName,
CurrentSize: uint64(options.Result.FileSize),
}
a.Context.Request().MultipartForm()
info.Init(func(name string) string {
return a.Form(name)
}, a.Header)
Expand Down
24 changes: 15 additions & 9 deletions upload/chunk_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"github.com/webx-top/echo"
)

const (
defaultMaxMemory int64 = 2 << 20 // 2 MB
)

// 分片上传
func (c *ChunkUpload) Upload(r *http.Request, opts ...ChunkInfoOpter) (int64, error) {
info := &ChunkInfo{
Expand All @@ -24,21 +28,23 @@ func (c *ChunkUpload) Upload(r *http.Request, opts ...ChunkInfoOpter) (int64, er
for _, opt := range opts {
opt(info)
}
info.Init(r.FormValue, r.Header.Get)
if !c.IsSupported(info) {
return 0, ErrChunkUnsupported
}
maxMemory := defaultMaxMemory
if c.FileMaxBytes > 0 {
if r.ContentLength > int64(c.FileMaxBytes) {
return 0, fmt.Errorf(`%w: %d>%d `, ErrRequestBodyExceedsLimit, r.ContentLength, c.FileMaxBytes)
}
if r.MultipartForm == nil {
err := r.ParseMultipartForm(int64(c.FileMaxBytes))
if err != nil {
return 0, fmt.Errorf("上传文件错误: %w", err)
}
maxMemory = int64(c.FileMaxBytes)
}
if r.MultipartForm == nil {
err := r.ParseMultipartForm(maxMemory)
if err != nil {
return 0, fmt.Errorf("上传文件错误: %w", err)
}
}
info.Init(r.FormValue, r.Header.Get)
if !c.IsSupported(info) {
return 0, ErrChunkUnsupported
}
// 获取上传文件
upFile, fileHeader, err := r.FormFile(info.FormField)
if err != nil {
Expand Down

0 comments on commit c98e247

Please sign in to comment.