Esempio n. 1
0
func mpPostHandler(req *web.Request) {
	parts, err := web.ParseMultipartForm(req, -1)
	var (
		filename, contentType string
		contentParam          map[string]string
		size                  int
	)
	if len(parts) > 0 {
		filename = parts[0].Filename
		contentType = parts[0].ContentType
		contentParam = parts[0].ContentParam
		size = len(parts[0].Data)
	}
	mpTempl.Execute(
		req.Respond(web.StatusOK, web.HeaderContentType, "text/html"),
		map[string]interface{}{
			"xsrf": req.Param.Get(web.XSRFParamName),
			"result": map[string]interface{}{
				"err":          err,
				"hello":        req.Param.Get("hello"),
				"foo":          req.Param.Get("foo"),
				"filename":     filename,
				"contentType":  contentType,
				"contentParam": contentParam,
				"size":         size,
			},
		})
}
Esempio n. 2
0
func multipartHandler(req *web.Request) {
	files, err := web.ParseMultipartForm(req, -1)
	if err != nil {
		req.Error(web.StatusBadRequest, err)
		return
	}
	w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
	if err := templates.ExecuteTemplate(w, "home.html", map[string]interface{}{"req": req, "files": files}); err != nil {
		log.Print(err)
	}
}