diff --git a/swarm/api/api.go b/swarm/api/api.go index 1e08b71d35..84ac95769b 100644 --- a/swarm/api/api.go +++ b/swarm/api/api.go @@ -308,7 +308,7 @@ func (self *Api) Put(content, contentType string, toEncrypt bool) (k storage.Key // Get uses iterative manifest retrieval and prefix matching // to resolve basePath to content using dpa retrieve // it returns a section reader, mimeType, status and an error -func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionReader, mimeType string, status int, err error) { +func (self *Api) Get(key storage.Key, path string) (reader *storage.LazyChunkReader, mimeType string, status int, err error) { log.Debug("api.get", "key", key, "path", path) apiGetCount.Inc(1) trie, err := loadManifest(self.dpa, key, nil) diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index 4ce832863f..aab253e12b 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -844,9 +844,23 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) { return } + var res []byte + for { + res, err = ioutil.ReadAll(reader) + if err != nil { + log.Error("handle.get.file", "ruid", r.ruid, "error", err) + time.Sleep(200 * time.Millisecond) + continue + } + log.Debug("handle.get.file.readall success", "ruid", r.ruid) + break + } + + rdr := bytes.NewReader(res) + w.Header().Set("Content-Type", contentType) - http.ServeContent(w, &r.Request, "", time.Now(), reader) + http.ServeContent(w, &r.Request, "", time.Now(), rdr) } func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {