panlei
2019-06-25 fd04fb054dd9bdfafd04c24bdab43b5cd2b09b2e
util/upload.go
@@ -1,6 +1,7 @@
package util
import (
   "basic.com/pubsub/protomsg.git"
   "bytes"
   "encoding/json"
   "errors"
@@ -10,9 +11,13 @@
   "mime/multipart"
   "net/http"
   "time"
   "gocv.io/x/gocv"
)
// 上传图片(二进制流)
func PostFormBufferData(uri string, fileData []byte, fileName string,) (maps map[string]interface{}, err0 error) {
func PostFormBufferData(uri string, img protomsg.Image, fileName string,) (maps map[string]interface{}, err0 error) {
   imgs := gocv.NewMat()
   imgs, _ = gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data)
   fdata,_ := gocv.IMEncode(".jpg",imgs)
   body := &bytes.Buffer{}
   writer := multipart.NewWriter(body)
   _, err := writer.CreateFormFile("file", fileName)
@@ -22,7 +27,7 @@
   boundary := writer.Boundary()
   //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary)
   close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary))
   file := bytes.NewBuffer(fileData)
   file := bytes.NewBuffer(fdata)
   request_reader := io.MultiReader(body, file, close_buf)
   //_, err = io.Copy(part, file)
   //writer.WriteField(key, val)