I used go-ipfs-api
to download a large file from ipfs, web access download.
I get an error fatal error:
runtime: out of memory.
How can I modify my code?
func main() {
http.HandleFunc("/", download)
http.ListenAndServe(":8080", nil)
}
func download(w http.ResponseWriter, r *http.Request) {
client := shell.NewShell("http://127.0.0.1:5001")
fd, err := client.Cat("QmTcj7SfRf4vnLnCqnxMT7kutrzFyevjBeT5RCiN9xGAL4")
if err != nil{
fmt.Println(err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
defer fd.Close()
fileName := "demo.mp4"
// As per RFC6266 section 4.3
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+ fileName)
data, _ := ioutil.ReadAll(fd)
http.ServeContent(w, r, fileName, time.Now().Local(), bytes.NewReader(data))
w.WriteHeader(http.StatusOK)
return
}