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
+15.3k nginx: [emerg] unknown directive "ssl"
+7.9k Golang : Get today's weekday name and calculate target day distance example
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+13.1k Golang : Convert(cast) uintptr to string example
+36.6k Golang : Validate IP address
+13.7k Golang : Check if an integer is negative or positive
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+9.8k Golang : Format strings to SEO friendly URL example
+5.9k Golang : Shuffle array of list
+5.6k Fix fatal error: evacuation not done in time problem
+6k Fontello : How to load and use fonts?
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image