diff options
| author | Chris Lu <chris.lu@gmail.com> | 2014-03-30 11:28:04 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2014-03-30 11:28:04 -0700 |
| commit | 2861275fb67112cb2fe51521b5052c3f1a98414d (patch) | |
| tree | a86f0eeab6a0603d1217983430c11bb59632d87c /go/weed/download.go | |
| parent | 259c7d66f72938857ee94cc747fc54982fbbcb1f (diff) | |
| download | seaweedfs-2861275fb67112cb2fe51521b5052c3f1a98414d.tar.xz seaweedfs-2861275fb67112cb2fe51521b5052c3f1a98414d.zip | |
working filer server!
Diffstat (limited to 'go/weed/download.go')
| -rw-r--r-- | go/weed/download.go | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/go/weed/download.go b/go/weed/download.go index 2e32f3ae9..4309fe5e0 100644 --- a/go/weed/download.go +++ b/go/weed/download.go @@ -1,12 +1,11 @@ package main import ( - "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" + "code.google.com/p/weed-fs/go/util" "fmt" "io" "io/ioutil" - "net/http" "os" "path" "strings" @@ -78,31 +77,12 @@ func runDownload(cmd *Command, args []string) bool { return true } -func fetchFileId(server string, fildId string) (filename string, content []byte, e error) { - fileUrl, lookupError := operation.LookupFileId(server, fildId) +func fetchFileId(server string, fileId string) (filename string, content []byte, e error) { + fileUrl, lookupError := operation.LookupFileId(server, fileId) if lookupError != nil { return "", nil, lookupError } - filename, content, e = fetchUrl(fileUrl) - return -} - -func fetchUrl(fileUrl string) (filename string, content []byte, e error) { - response, err := http.Get(fileUrl) - if err != nil { - return "", nil, err - } - defer response.Body.Close() - contentDisposition := response.Header["Content-Disposition"] - if len(contentDisposition) > 0 { - glog.V(4).Info("Content-Disposition: ", contentDisposition[0]) - if strings.HasPrefix(contentDisposition[0], "filename=") { - filename = contentDisposition[0][len("filename="):] - } - } else { - glog.V(4).Info("No Content-Disposition!") - } - content, e = ioutil.ReadAll(response.Body) + filename, content, e = util.DownloadUrl(fileUrl) return } |
