From 4c07c83eb64ee3851168714e05e3fa25902ac747 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 26 Dec 2024 14:04:36 +0800 Subject: [PATCH 1/2] Update transport.go --- cmd/ipasd/service/transport.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/ipasd/service/transport.go b/cmd/ipasd/service/transport.go index ff3d401..961e6a9 100644 --- a/cmd/ipasd/service/transport.go +++ b/cmd/ipasd/service/transport.go @@ -73,7 +73,7 @@ func MakeAddEndpoint(srv Service) endpoint.Endpoint { return nil, fmt.Errorf("do not support %s file", path.Ext(p.file.FileName())) } - app, err := srv.Add(buf, buf.Size(), t) + app, err := srv.Add(buf, p.file.Size(), t) if err != nil { return nil, err } @@ -217,4 +217,4 @@ func tryMatchID(id string) error { return ErrIdInvalid } return nil -} +} \ No newline at end of file From 9f8b67a312ef5fbff470318be8264ca5893c07ae Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 26 Dec 2024 14:05:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20multipart.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/multipart/multipart.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/multipart/multipart.go b/pkg/multipart/multipart.go index a90450b..4d6b351 100644 --- a/pkg/multipart/multipart.go +++ b/pkg/multipart/multipart.go @@ -7,6 +7,7 @@ import ( "mime" "mime/multipart" "net/http" + "strconv" ) type MultipartForm struct { @@ -17,7 +18,7 @@ type FormFile struct { part *multipart.Part name string // form name filename string // file name - // size int64 // readed size + size int64 // readed size } var _ io.Reader = (*FormFile)(nil) @@ -43,10 +44,17 @@ func (m *MultipartForm) GetFormFile(targetName string) (*FormFile, error) { } filename := p.FileName() + s := m.r.Header.Get("Content-Length") + size, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return nil, err + } + return &FormFile{ part: p, name: name, filename: filename, + size: size, }, nil } @@ -79,3 +87,7 @@ func (f *FormFile) FileName() string { func (f *FormFile) Name() string { return f.name } + +func (f *FormFile) Size() int64 { + return f.size +} \ No newline at end of file