On-the-Fly Content Type Sniffing and Validation in Go

File upload handlers often stream the request body straight to S3, so there's nothing buffered to validate. Here's a small io.Reader wrapper that sniffs magic bytes with http.DetectContentType as the data flows through, and fails the upload with your own error when the content type doesn't pass validation. (Tags: #go #quick-tip)