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
+10.4k Golang : Generate random integer or float number
+7.3k Golang : File system scanning
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+10.6k Golang : Bubble sort example
+13.3k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+4k Detect if Google Analytics and Developer Media are loaded properly or not
+9.2k Golang : does not implement flag.Value (missing Set method)
+11.3k Golang : Characters limiter example
+19.2k Golang : Check if directory exist and create if does not exist
+9.4k Facebook : Getting the friends list with PHP return JSON format
+13.7k Golang : Check if an integer is negative or positive
+10.2k Golang : How to get quoted string into another string?