dta25920 2016-01-29 19:37
浏览 21

输入TYPE TEXT值形式(enctype =“ multipart / form-data”)返回null

func fupload(w http.ResponseWriter, r *http.Request) {
    if r.Method == "POST" {
        r.ParseForm()
        company := r.FormValue("company")
        fmt.Println(company)
        _, header, _ := r.FormFile("upfile")
        fmt.Println(header.Filename)
        return
    }
    w.Write([]byte("<html><body>"))
    w.Write([]byte(fmt.Sprintf("<form method=\"POST\" enctype=\"multipart/form-data\">")))
    w.Write([]byte("Enter Company <input type=\"text\" maxlength=\"80\" size=\"80\" name=\"company\" ><br/>"))
    w.Write([]byte("File to upload: <input type=\"file\" name=\"upfile\" /><br/>"))
    w.Write([]byte("<input type=\"submit\"  value=\"Submit\"/>"))
    w.Write([]byte("</form>"))
    w.Write([]byte("</body></html>"))
    return
}

For the input type Text (eg) Company here always return NULL, when enctype="multipart/form-data"

  • 写回答

2条回答 默认 最新

  • donglv7097 2016-01-29 19:45
    关注

    ParseForm only parses the query parameters. From the docs:

    ParseForm parses the raw query from the URL and updates r.Form.

    For POST or PUT requests, it also parses the request body as a form and put the results into both r.PostForm and r.Form. POST and PUT body parameters take precedence over URL query string values in r.Form.

    If the request Body's size has not already been limited by MaxBytesReader, the size is capped at 10MB.

    ParseMultipartForm calls ParseForm automatically. It is idempotent.

    Either use ParseMultipartForm if you want to handle "multipart/form-data", or don't call either and let FormValue call what's needed.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗