doutang7383
2016-03-28 01:10
浏览 497
已采纳

golang-用于上传大文件的功能

In go there are different ways to read a file sent with a multipart form

r.FormFile("file")

r.MultipartReader()

r.ParseMultipartForm(size)

and I partially understand the difference between them, however which is it the best for handling large files (~1GB)?

And, which is the one that uses less memory?

图片转代码服务由CSDN问答提供 功能建议

在执行过程中,有多种方法可以读取以多部分形式发送的文件 < p> <代码> r.FormFile( “文件”)

<代码> r.MultipartReader()

r.ParseMultipartForm(size)

,我部分理解了它们之间的区别,但是哪个是处理大文件(〜1GB)的最佳选择? / p>

然后,这是使用较少内存的计算机吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsu5188 2016-03-28 04:59
    已采纳

    https://golang.org/pkg/net/http/#Request.ParseMultipartForm

    ParseMultipartForm parses a request body as multipart/form-data. The whole request body is parsed and up to a total of maxMemory bytes of its file parts are stored in memory, with the remainder stored on disk in temporary files. ParseMultipartForm calls ParseForm if necessary. After one call to ParseMultipartForm, subsequent calls have no effect.

    You can therefore control the maximum memory usage by calling r.ParseMultipartForm(max), and you can control the total amount read from the request by using http.MaxBytesReader.

    Also see this answer: https://stackoverflow.com/a/28292505/556573

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题