Demonstrates how to make an optimal HTTP request with the multipart MIME message according to RFC7578 in Go. It uploads a file including metadata to an echoing server, which just prints the request header and body on the console.
The best solutions for both chunked and sized (with content length) are upload-composed-chunked and upload-composed-sized, which use a custom multipart composer. Other solutions use the standard multipart writer.
Command line executables; see the descriptions pointed at by these links:
- serve-echo – HTTP server, which just prints the request header and body on the console.
- upload-buffered – reads the entire file to memory, posts the content length
- upload-piped-chunked – streams the file using a pipe, does not post the content length
- upload-piped-sized – streams the file using a pipe, posts the content length
- upload-composed-chunked – streams the file using a reader, does not post the content length
- upload-composed-sized – streams the file using a reader, posts the content length
The server and the uploading executables use common parameters and common request & response handling to make the testing easier.
Install Go and GNU Make. For example, on Mac:
brew install go make
Clone this repository and build the executable:
git clone https://github.com/prantlf/go-upload-demo.git
cd go-upload-demo
make
Run the testing web server, which prints requests on the console, in the background:
./serve-echo &
Run the testing clients, which use different techniques to send a multi-part form request:
./upload-buffered
./upload-piped-chunked
./upload-piped-sized
./upload-composed-chunked
./upload-composed-sized
Leave a Reply