aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/swarm/upload.go
diff options
context:
space:
mode:
authorAlexey Sharov <www.pismeco@gmail.com>2018-10-01 19:39:39 +0800
committerAnton Evangelatov <anton.evangelatov@gmail.com>2018-10-01 19:39:39 +0800
commitdc5d643bb59812cda578fac941c2f1da316bc9d7 (patch)
tree7405f387672f0548eb4734a93581780c96cee7a9 /cmd/swarm/upload.go
parentb69942befeb9f1af55cad0f91953bdaea2ea3efb (diff)
downloaddexon-dc5d643bb59812cda578fac941c2f1da316bc9d7.tar.gz
dexon-dc5d643bb59812cda578fac941c2f1da316bc9d7.tar.zst
dexon-dc5d643bb59812cda578fac941c2f1da316bc9d7.zip
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
Diffstat (limited to 'cmd/swarm/upload.go')
-rw-r--r--cmd/swarm/upload.go26
1 files changed, 4 insertions, 22 deletions
diff --git a/cmd/swarm/upload.go b/cmd/swarm/upload.go
index f76cb1b98..2225127cf 100644
--- a/cmd/swarm/upload.go
+++ b/cmd/swarm/upload.go
@@ -22,16 +22,15 @@ import (
"fmt"
"io"
"io/ioutil"
- "mime"
- "net/http"
"os"
"os/user"
"path"
"path/filepath"
"strings"
- "github.com/ethereum/go-ethereum/cmd/utils"
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
+
+ "github.com/ethereum/go-ethereum/cmd/utils"
"gopkg.in/urfave/cli.v1"
)
@@ -118,10 +117,9 @@ func upload(ctx *cli.Context) {
return "", fmt.Errorf("error opening file: %s", err)
}
defer f.Close()
- if mimeType == "" {
- mimeType = detectMimeType(file)
+ if mimeType != "" {
+ f.ContentType = mimeType
}
- f.ContentType = mimeType
return client.Upload(f, "", toEncrypt)
}
}
@@ -161,19 +159,3 @@ func homeDir() string {
}
return ""
}
-
-func detectMimeType(file string) string {
- if ext := filepath.Ext(file); ext != "" {
- return mime.TypeByExtension(ext)
- }
- f, err := os.Open(file)
- if err != nil {
- return ""
- }
- defer f.Close()
- buf := make([]byte, 512)
- if n, _ := f.Read(buf); n > 0 {
- return http.DetectContentType(buf)
- }
- return ""
-}