add file close; add multipart close;
This commit is contained in:
parent
9d6dee25c9
commit
0c71408d1f
12
multipart.go
12
multipart.go
|
@ -15,6 +15,11 @@ func writeFormUploadFile(mwriter *multipart.Writer, ufile *UploadFile) {
|
|||
log.Panic(err)
|
||||
}
|
||||
io.Copy(part, ufile.FileReaderCloser)
|
||||
|
||||
err = ufile.FileReaderCloser.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func createMultipart(postParams IBody, params []interface{}) {
|
||||
|
@ -23,8 +28,6 @@ func createMultipart(postParams IBody, params []interface{}) {
|
|||
body := &bytes.Buffer{}
|
||||
mwriter := multipart.NewWriter(body)
|
||||
|
||||
defer mwriter.Close()
|
||||
|
||||
for _, iparam := range params[0 : plen-1] {
|
||||
switch param := iparam.(type) {
|
||||
case *UploadFile:
|
||||
|
@ -87,4 +90,9 @@ func createMultipart(postParams IBody, params []interface{}) {
|
|||
|
||||
postParams.AddContentType(mwriter.FormDataContentType())
|
||||
postParams.SetIOBody(body)
|
||||
|
||||
err := mwriter.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,11 @@ type UploadFile struct {
|
|||
// UploadFileFromPath 从本地文件获取上传文件
|
||||
func UploadFileFromPath(fileName string) (*UploadFile, error) {
|
||||
fd, err := os.Open(fileName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &UploadFile{FileReaderCloser: fd, FileName: fileName}, nil
|
||||
|
||||
}
|
||||
|
||||
// UploadFileFromGlob 根据Glob从本地文件获取上传文件
|
||||
|
|
Loading…
Reference in New Issue
Block a user