forked from TrueCloudLab/frostfs-http-gw
[#19] Extract uploading logic into a separate package
Signed-off-by: Pavel Korotkov <pavel@nspcc.ru>
This commit is contained in:
parent
4c96885a42
commit
eb92219e14
9 changed files with 153 additions and 188 deletions
41
uploader/multipart.go
Normal file
41
uploader/multipart.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package uploader
|
||||
|
||||
import (
|
||||
"io"
|
||||
"mime/multipart"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MultipartFile interface {
|
||||
io.ReadCloser
|
||||
FileName() string
|
||||
}
|
||||
|
||||
func fetchMultipartFile(l *zap.Logger, r io.Reader, boundary string) (MultipartFile, error) {
|
||||
reader := multipart.NewReader(r, boundary)
|
||||
|
||||
for {
|
||||
part, err := reader.NextPart()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
name := part.FormName()
|
||||
if name == "" {
|
||||
l.Debug("ignore part, empty form name")
|
||||
continue
|
||||
}
|
||||
|
||||
filename := part.FileName()
|
||||
|
||||
// ignore multipart/form-data values
|
||||
if filename == "" {
|
||||
l.Debug("ignore part, empty filename", zap.String("form", name))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
return part, nil
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue