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
+11.6k Android Studio : Create custom icons for your application example
+7.4k Golang : Example of custom handler for Gorilla's Path usage.
+4.6k MariaDB/MySQL : How to get version information
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+6.8k Get Facebook friends working in same company
+14k Golang : Compress and decompress file with compress/flate example
+10.6k Golang : Simple File Server
+6.9k Golang : How to setup a disk space used monitoring service with Telegram bot
+41.2k Golang : How to count duplicate items in slice/array?
+6.3k Golang : Detect face in uploaded photo like GPlus
+8.3k Golang : Auto-generate reply email with text/template package