2021-03-31 16:58:42 +00:00
|
|
|
package uploader
|
2021-02-13 16:17:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2023-03-07 14:08:53 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/uploader/multipart"
|
2021-02-13 16:17:01 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-05-13 12:22:03 +00:00
|
|
|
// MultipartFile provides standard ReadCloser interface and also allows one to
|
|
|
|
// get file name, it's used for multipart uploads.
|
2021-02-13 16:17:01 +00:00
|
|
|
type MultipartFile interface {
|
|
|
|
io.ReadCloser
|
|
|
|
FileName() string
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchMultipartFile(l *zap.Logger, r io.Reader, boundary string) (MultipartFile, error) {
|
2022-04-29 15:25:26 +00:00
|
|
|
// To have a custom buffer (3mb) the custom multipart reader is used.
|
|
|
|
// https://github.com/nspcc-dev/neofs-http-gw/issues/148
|
2021-02-13 16:17:01 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|