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
+7.2k Golang : Null and nil value
+16.5k Golang : Execute terminal command to remote machine example
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+9.7k Golang : Find correlation coefficient example
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+4.9k Javascript : How to get width and height of a div?
+6.2k Golang : Get missing location after unmarshal binary and gob decode time.
+19.6k Golang : Set or Add HTTP Request Headers
+11.1k Golang : Read until certain character to break for loop
+10k Golang : Setting variable value with ldflags
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+11k How to test Facebook App on localhost ?