RequestBody is empty when submit multipart/form-data
Closed this issue · 5 comments
tablecell commented
package main
import (
"fmt"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewDefaultResponder())
e.Use(middleware.NewDefaultBodyParser())
e.GET("/form", func(c *elton.Context) error {
c.Header().Set("Content-Type", "text/html")
c.Body = `<html><head><meta charset='utf-8'/></head><body>
<form action="/upload", method="post" enctype="multipart/form-data">
<input type="file" name="upfile">
<input type="submit" />
</form></body></html>`
return nil
})
e.POST("/upload", func(c *elton.Context) error {
fmt.Println(string(c.RequestBody))
c.Body = c.RequestBody
return nil
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}
vicanso commented
NewDefaultBodyParser
only support gzip and json decode. You should use c.Request.MultipartForm
tablecell commented
fmt.Println(c.Request.MultipartForm)
result is nil
Is there any complete example for file upload ?
vicanso commented
vicanso commented
Elton will be supported ReadFile
in the next version.
vicanso commented
@tablecell You can use ReadFile
function in version 1.5.0.
func (c *Context) ReadFile(key string) ([]byte, *multipart.FileHeader, error)