Here’s an example using multipart request. I modified this from a piece of code I have that deals with JSON docs, so there may be some mistakes in it, but it should give you the idea:
body := bytes.Buffer{}
writer := multipart.NewWriter(&body)
hdr := textproto.MIMEHeader{}
hdr.Set("Content-Type", "text/plain")
part, _ := writer.CreatePart(hdr)
part.Write(data1)
hdr = textproto.MIMEHeader{}
hdr.Set("Content-Type", <image type>)
part, _ = writer.CreatePart(hdr)
part.Write(imageData)
... // Add more parts if you need to
writer.Close()
request, _ := http.NewRequest(http.MethodPost, url, &body)
request.Header.Set("Content-Type", fmt.Sprintf("multipart/mixed;boundary=%s", writer.Boundary()))
hcli := http.Client{}
rsp, err := hcli.Do(request)
2
solved Combining string and []byte for payload