| | |
| | | package util |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | |
| | | "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) |
| | |
| | | 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) |