第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

http put 服務(wù)器處理大文件

http put 服務(wù)器處理大文件

Go
catspeake 2023-07-10 10:41:14
它處理 http PUT 請(qǐng)求。對(duì)于小文件,它工作正常:$ curl? -v http://192.168.1.10:9193/ -T red.tx*? ?Trying 192.168.1.10...* Connected to 192.168.1.10 (192.168.1.10) port 9193 (#0)> PUT /red.tx HTTP/1.1> Host: 192.168.1.10:9193> User-Agent: curl/7.47.0> Accept: */*> Content-Length: 19697247> Expect: 100-continue>< HTTP/1.1 100 Continue* We are completely uploaded and fine< HTTP/1.1 200 OK< Date: Fri, 26 Jul 2019 00:43:43 GMT< Content-Length: 0< Content-Type: text/plain; charset=utf-8<* Connection #0 to host 192.168.1.10 left intact然而 - 發(fā)送一個(gè)大于 1G 的大文件,它會(huì)耗盡內(nèi)存。這是可以理解的,因?yàn)檎麄€(gè)正文被讀作contents, err := ioutil.ReadAll(r.Body)runtime: out of memory: cannot allocate 536870912-byte block (537919488 in use)fatal error: out of memory? ??runtime stack:runtime.throw(0x259a35, 0xd)? ? ? ? /usr/lib/go-1.7/src/runtime/panic.go:566 +0x78runtime.largeAlloc(0x1ffffe00, 0x10616f01, 0x10637afc)? ? ? ? /usr/lib/go-1.7/src/runtime/malloc.go:776 +0xc8runtime.mallocgc.func1()? ? ? ? /usr/lib/go-1.7/src/runtime/malloc.go:669 +0x34runtime.systemstack(0x10aa8200)? ? ? ? /usr/lib/go-1.7/src/runtime/asm_arm.s:247 +0x80runtime.mstart()? ? ? ? /usr/lib/go-1.7/src/runtime/proc.go:1079請(qǐng)告訴我從 r.Body 讀取并將其寫入文件的正確方法。謝謝!
查看完整描述

1 回答

?
倚天杖

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

嘗試將請(qǐng)求負(fù)載直接復(fù)制到文件中。


f, err := os.Create(temporaryFilename)

if err != nil {

    return err

}

defer f.Close()


_, err := io.Copy(f, r.Body)

如果您需要對(duì)復(fù)制的文件執(zhí)行某些操作,只需操作創(chuàng)建的文件對(duì)象(在上面的示例中是f)。


查看完整回答
反對(duì) 回復(fù) 2023-07-10
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)