Here's an example code snippet for creating an HTTP POST request sending multipart form data in Go:
main.go1043 chars49 lines
In this example, we first create a new multipart buffer using the multipart.NewWriter()
function from the mime/multipart
package. We then add a file field and a text field to the multipart buffer using the CreateFormFile()
and CreateFormField()
methods of the multipart writer. Finally, we close the multipart writer and create an HTTP POST request with the multipart form data using http.NewRequest()
. We set the Content-Type
header of the request to multipart/form-data
, which is the correct MIME type for sending multipart form data. We then send the request using an http.Client
and get the response in the usual way.
gistlibby LogSnag