Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我收到一个错误致命错误:运行时:使用“go ipfs api”下载视频时内存不足_Go - Fatal编程技术网

我收到一个错误致命错误:运行时:使用“go ipfs api”下载视频时内存不足

我收到一个错误致命错误:运行时:使用“go ipfs api”下载视频时内存不足,go,Go,我使用GoIPFSAPI从ipfs下载了一个大文件,web访问下载 我收到一个错误致命错误: 运行时:内存不足 如何修改我的代码 func main() { http.HandleFunc("/", download) http.ListenAndServe(":8080", nil) } func download(w http.ResponseWriter, r *http.Request) { client := shell.NewShell("http:/

我使用GoIPFSAPI从ipfs下载了一个大文件,web访问下载

我收到一个错误致命错误:

运行时:内存不足

如何修改我的代码

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
}

您可以使用io.Copy而不是ReadAll,但您必须自己设置内容类型:

w.Header.Set("Content-Type",<the content type>)
io.Copy(w,fd)
return
我不熟悉您正在使用的库,您可能需要在复制后致电fd.Close