|
|
package upload
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/ability/tests"
|
|
|
"mime/multipart"
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
func init(){
|
|
|
tests.Init()
|
|
|
}
|
|
|
|
|
|
|
|
|
func Test_Image(t *testing.T){
|
|
|
input := &protocol.ImageRequest{}
|
|
|
input.Files = append(input.Files,&multipart.FileHeader{
|
|
|
Filename:"abc.gif",
|
|
|
|
|
|
})
|
|
|
var bufReader bytes.Buffer
|
|
|
mpWriter:=multipart.NewWriter(&bufReader)
|
|
|
fw,err :=mpWriter.CreateFormFile("file_a","a.jpg")//a.txt
|
|
|
if err!=nil{
|
|
|
t.Fatal(err)
|
|
|
return
|
|
|
}
|
|
|
fw.Write([]byte("this is a txt"))
|
|
|
mpWriter.WriteField("name","tiprok")
|
|
|
|
|
|
|
|
|
fwb,err :=mpWriter.CreateFormFile("file_a","b.png")
|
|
|
if err!=nil{
|
|
|
t.Fatal(err)
|
|
|
return
|
|
|
}
|
|
|
fwb.Write([]byte("this is b txt"))
|
|
|
mpWriter.Close()
|
|
|
|
|
|
mpReader:=multipart.NewReader(&bufReader,mpWriter.Boundary())
|
|
|
form,err :=mpReader.ReadForm(100)
|
|
|
if err!=nil{
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
for _,files :=range form.File{
|
|
|
//for i:=range files{
|
|
|
// file :=files[i]
|
|
|
// if f,err :=file.Open();err!=nil{
|
|
|
// return
|
|
|
// }else{
|
|
|
// bufTmp :=bytes.NewBuffer(nil)
|
|
|
// bufTmp.ReadFrom(f)
|
|
|
// //log.Println(file.Filename," file:",bufTmp.String())
|
|
|
//
|
|
|
// }
|
|
|
//}
|
|
|
input.Files = append(input.Files,files...)
|
|
|
}
|
|
|
|
|
|
rsp,err :=Image(input)
|
|
|
if err!=nil{
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
t.Log(rsp)
|
|
|
} |
...
|
...
|
|