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.7k Golang : How to check if a connection to database is still alive ?
+6.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+10.2k Golang : Use regular expression to get all upper case or lower case characters example
+32.5k Golang : Copy directory - including sub-directories and files
+20.2k Golang : How to get own program name during runtime ?
+8k Golang : Get all countries phone codes
+9.6k Golang : How to extract video or image files from html source code
+28.5k Golang : Change a file last modified date and time
+16.4k Golang : How to implement two-factor authentication?
+11.3k Golang : Post data with url.Values{}
+8.7k Golang : Combine slices but preserve order example