franela/goreq — pull request #41 by ryansb (2014-04-06 17:58:05+00:00)
Title: Multipart Support

I've added some basic multipart form support. It works, but the API is (IMO) a little rough but could benefit from some feedback.

Here's a full usage example for uploading a file, and here's a link to view the requests it produces http://requestb.in/nkp6grnk?inspect
```go
package main

import (
"github.com/franela/goreq"
"io/ioutil"
"os"
"path"
)

func main() {
// The Gutenberg project is *awesome*
// http://www.gutenberg.org/ebooks/45269
fileName := "Inventions_of_the_Great_War--A.Russell_Bond.mobi"
file, err := os.Open(path.Join("/tmp", fileName))
if err != nil {
panic(err)
}

defer file.Close()

body := goreq.MultipartForm{
Params: map[string]string{
"title": "Inventions of the Great War",
"author": "A. Russell Bond",
"description": "A Gutenberg project book originally found at http://www.gutenberg.org/ebooks/45269",
},
Field: "file",
FileName: fileName,
Source: file,
}

resp, _ := goreq.Request{
Uri: "http://requestb.in/nkp6grnk",
MaxRedirects: 5,
Method: "POST",
Body: body,
}.Do()

println(resp.StatusCode)
b, _ := ioutil.ReadAll(resp.Body)
println(string(b))
}
```