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

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?

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.