cmd/swarm, swarm: cross-platform Content-Type detection (#17782)
- Mime types generator (Standard "mime" package rely on system-settings, see mime.osInitMime) - Changed swarm/api.Upload: - simplify I/O throttling by semaphore primitive and use file name where possible - f.Close() must be called in Defer - otherwise panic or future added early return will cause leak of file descriptors - one error was suppressed
This commit is contained in:
committed by
Anton Evangelatov
parent
b69942befe
commit
dc5d643bb5
@ -24,7 +24,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
@ -124,10 +123,16 @@ func Open(path string) (*File, error) {
|
||||
f.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
contentType, err := api.DetectContentType(f.Name(), f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &File{
|
||||
ReadCloser: f,
|
||||
ManifestEntry: api.ManifestEntry{
|
||||
ContentType: mime.TypeByExtension(filepath.Ext(path)),
|
||||
ContentType: contentType,
|
||||
Mode: int64(stat.Mode()),
|
||||
Size: stat.Size(),
|
||||
ModTime: stat.ModTime(),
|
||||
|
Reference in New Issue
Block a user