I am trying to upload a file with multipart/form-data using Insomnia REST client. But uploaded files has headers.
File content is:
<?xml version="1.0" encoding="utf-8"?>
<PresetGroup xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Presets>
...
And my code that handles upload multipart:
if err = r.ParseMultipartForm(32 << 20); nil != err {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
r.ParseMultipartForm(32 << 20)
file, _, err := r.FormFile("file")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer file.Close()
reader = io.Reader(file)
Now, when I handle reader and write to a file, File becomes this:
--X-INSOMNIA-BOUNDARY
Content-Disposition: form-data; name="file"; filename="presets.xml" Content-Type: application/octet-stream
<?xml version="1.0" encoding="utf-8"?>
<PresetGroup xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Presets>
...
Why content-type
and boundary added (prepended) to file? How can I avoid it?