Marina Biryukova
d219943542
All checks were successful
/ Vulncheck (pull_request) Successful in 1m32s
/ Lint (pull_request) Successful in 2m28s
/ Tests (1.20) (pull_request) Successful in 1m52s
/ Tests (1.21) (pull_request) Successful in 1m21s
/ DCO (pull_request) Successful in 3m25s
/ Builds (1.20) (pull_request) Successful in 5m38s
/ Builds (1.21) (pull_request) Successful in 1m23s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"io"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/handler/multipart"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// MultipartFile provides standard ReadCloser interface and also allows one to
|
|
// get file name, it's used for multipart uploads.
|
|
type MultipartFile interface {
|
|
io.ReadCloser
|
|
FileName() string
|
|
}
|
|
|
|
func fetchMultipartFile(l *zap.Logger, r io.Reader, boundary string) (MultipartFile, error) {
|
|
// To have a custom buffer (3mb) the custom multipart reader is used.
|
|
// Default reader uses 4KiB chunks, which slow down upload speed up to 400%
|
|
// https://github.com/golang/go/blob/91b9915d3f6f8cd2e9e9fda63f67772803adfa03/src/mime/multipart/multipart.go#L32
|
|
reader := multipart.NewReader(r, boundary)
|
|
|
|
for {
|
|
part, err := reader.NextPart()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
name := part.FormName()
|
|
if name == "" {
|
|
l.Debug(logs.IgnorePartEmptyFormName)
|
|
continue
|
|
}
|
|
|
|
filename := part.FileName()
|
|
|
|
// ignore multipart/form-data values
|
|
if filename == "" {
|
|
l.Debug(logs.IgnorePartEmptyFilename, zap.String("form", name))
|
|
|
|
continue
|
|
}
|
|
|
|
return part, nil
|
|
}
|
|
}
|