How to limit file size for multi-file upload?

In the implementation of the HTTP service, I allow the download of the multipart http file using the PUT method.

However, before writing everything to the hard drive, I would like to check if the file size is normal. For instance. Must be less than 50 MB.

How to do it in go?

+4
source share
1 answer

You might want to check out http.MaxBytesReader . It limits the maximum amount of data that can be received / sent per request.

MaxBytesReader prevents accidental or malicious sending of large requests to clients and waste of server resources.

+5
source

All Articles