亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用“go-ipfs-api”下載視頻時出現致命錯誤:運行時:內存不足

使用“go-ipfs-api”下載視頻時出現致命錯誤:運行時:內存不足

Go
絕地無雙 2023-07-17 14:18:16
我以前都是go-ipfs-api從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}
查看完整描述

1 回答

?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

您可以使用 io.Copy 代替 ReadAll,但必須自己設置內容類型:


w.Header.Set("Content-Type",<the content type>)

io.Copy(w,fd)

return

我不熟悉您正在使用的庫,您可能需要在復制后調用 fd.Close() 。


查看完整回答
反對 回復 2023-07-17
  • 1 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號