Call to http.DetectContentType has trailing NUL bytes in buffer
internetisalie opened this issue · comments
Michael Crawford commented
In writeMultipartFormFile
, the call to http.DetectContentType
is passed a buffer with potentially trailing 0
bytes. As a result, text/plain
is never detected in such cases.
cbuf
should be trimmed to size
to ensure text/plain
is property detected:
// Auto detect actual multipart content type
cbuf := make([]byte, 512)
size, err := r.Read(cbuf)
if err != nil && err != io.EOF {
return err
}
partWriter, err := w.CreatePart(createMultipartHeader(fieldName, fileName, http.DetectContentType(cbuf[:size])))
if err != nil {
return err
}