英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论