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
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+5.6k Golang : Shortening import identifier
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+7.4k Android Studio : How to detect camera, activate and capture example
+4.6k JavaScript : Rounding number to decimal formats to display currency
+5.4k Javascript : How to loop over and parse JSON data?
+11.6k Golang : Convert(cast) float to int
+11.8k Golang : GTK Input dialog box examples
+11.9k Golang : How to parse plain email text and process email header?
+14.8k Golang : Normalize unicode strings for comparison purpose
+29.1k Golang : Get first few and last few characters from string