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
}
In
writeMultipartFormFile
, the call tohttp.DetectContentType
is passed a buffer with potentially trailing0
bytes. As a result,text/plain
is never detected in such cases.cbuf
should be trimmed tosize
to ensuretext/plain
is property detected: