Skip to content

Commit

Permalink
Merge pull request #71 from iineva/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
iineva authored Dec 26, 2024
2 parents cce57c7 + 9f8b67a commit 5d9e253
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/ipasd/service/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -217,4 +217,4 @@ func tryMatchID(id string) error {
return ErrIdInvalid
}
return nil
}
}
14 changes: 13 additions & 1 deletion pkg/multipart/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"mime"
"mime/multipart"
"net/http"
"strconv"
)

type MultipartForm struct {
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit 5d9e253

Please sign in to comment.