如何限制多部分文件上传中的文件大小?

huangapple go评论80阅读模式
英文:

How to limit file size in multipart file upload?

问题

在HTTP服务实现中,我允许使用PUT方法进行多部分HTTP文件上传。

然而,在将所有内容写入硬盘之前,我想检查文件的大小是否合适。例如,文件大小必须在50MB以下。

在Go语言中如何实现这个功能?

英文:

In an HTTP service implementation, I'm allowing multipart http file upload with the PUT method.

However, before writing everything into the hard drive, I'd like to check if the size of the file is OK. E.g. has to be under 50MB.

How to do this in go?

答案1

得分: 4

你可能想查看http.MaxBytesReader。它限制了单个请求接收/发送的最大数据量。

MaxBytesReader可以防止客户端意外或恶意发送大量请求,从而浪费服务器资源。

英文:

You might want to check out http.MaxBytesReader. It limitates the maximum amount of data which can be received from/sent by a single request.

> MaxBytesReader prevents clients from accidentally or maliciously sending a large request and wasting server resources.

huangapple
  • 本文由 发表于 2014年9月24日 19:00:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/26015235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定