123
This commit is contained in:
parent
97835670b3
commit
5bdfa75392
@ -127,3 +127,28 @@ func HttpGetFile(url, path string) error {
|
|||||||
_, err = io.Copy(f, res.Body)
|
_, err = io.Copy(f, res.Body)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 流式上传文件
|
||||||
|
func PostFilePipe(url string, files map[string]string) {
|
||||||
|
r, w := io.Pipe()
|
||||||
|
m := multipart.NewWriter(w)
|
||||||
|
go func() {
|
||||||
|
defer w.Close()
|
||||||
|
defer m.Close()
|
||||||
|
for k, f := range files {
|
||||||
|
part, err := m.CreateFormFile(k, f)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
file, err := os.Open(f)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
if _, err = io.Copy(part, file); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
http.Post(url, m.FormDataContentType(), r)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user