From 6b14cb0009f8b9dd867bedc619bff299a14a0e9d Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Thu, 4 Jan 2018 15:36:50 +0200 Subject: [PATCH] fix #859 Former-commit-id: bcd483d42ac0d7c58c863ac54b55dc8069bd81ce --- context/context.go | 46 ++++------------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/context/context.go b/context/context.go index 19a38df4..2422ad8d 100644 --- a/context/context.go +++ b/context/context.go @@ -1663,8 +1663,10 @@ func (ctx *context) form() (form map[string][]string, found bool) { return form, true } - if form := ctx.request.MultipartForm.Value; len(form) > 0 { - return form, true + if m := ctx.request.MultipartForm; m != nil { + if len(m.Value) > 0 { + return m.Value, true + } } return nil, false @@ -1856,46 +1858,6 @@ func uploadTo(fh *multipart.FileHeader, destDirectory string) (int64, error) { return io.Copy(out, src) } -/* Good idea of mine but it doesn't work of course... -// Go can't use `io.ReadCloser` function return value the same -// as with other function that returns a `multipart.File`, even if -// multipart.File is an `io.ReadCloser`. -// So comment all those and implement a function inside the context itself. -// -// Copiable is the interface which should be completed -// by files or not that intend to be used inside the `context#CopyFile`. -// This interface allows testing file uploads to your http test as well. -// -// See `CopyFile` for more. -// type Copiable interface { -// Open() (io.ReadCloser, error) -// } -// - - -// CopyFile copies a `context#Copiable` "file", that can be acquired by the second argument of -// a `context.FormFile` (*multipart.FileHeader) as well, to the "dest". -// -// Returns the copied length as int64 and -// an error if file is not exist, or new file can't be created or closed at the end. -func CopyFile(file Copiable, dest string) (int64, error) { - src, err := fileOpen() - if err != nil { - return 0, err - } - defer src.Close() - - out, err := os.Create(dest) - if err != nil { - return 0, err - } - defer out.Close() - - return io.Copy(out, src) -} - -*/ - // Redirect sends a redirect response to the client // to a specific url or relative path. // accepts 2 parameters string and an optional int