Golang mime/multipart.NewWriter(), Boundary(), CreateFormFile(), Close() functions example
package mime/multipart
Golang mime/multipart.NewWriter(), Boundary(), CreateFormFile(), Close() functions usage example
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buff bytes.Buffer
w := multipart.NewWriter(&buffer)
// Add your image file
imgFile, err := os.Open(file)
if err != nil {
return
}
fileWriter, err := w.CreateFormFile("image", imgFile)
if err != nil {
return
}
bound := w.Boundary()
fmt.Println("Boundary : ", bound)
...
err = w.Close()
...
References :
http://golang.org/pkg/mime/multipart/#Writer.Boundary
http://golang.org/pkg/mime/multipart/#Writer.Close
Advertisement
Something interesting
Tutorials
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+41.9k Golang : How do I convert int to uint8?
+12.8k Golang : Convert int(year) to time.Time type
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+27.6k Golang : dial tcp: too many colons in address
+5.5k Golang : Stop goroutine without channel
+11.1k Golang : Roll the dice example
+6.9k Golang : Fibonacci number generator examples
+9.2k Golang : Create and shuffle deck of cards example
+6.5k Golang : Convert an executable file into []byte example
+22.7k Golang : Strings to lowercase and uppercase example
+6.8k Get Facebook friends working in same company