dongzhan8620 2015-03-09 10:42
浏览 63
已采纳

Golang GET多部分表单数据

Let say I have a html form

<form enctype="multipart/form-data" action="http://localhost:8080/incarcat" method="post">
    <input type="file" name="file" multiple="multiple"/>
    <input type="checkbox" name="delete" value="delete">
    <input type="submit" value="Load" />
</form>

and the following go code

read_form, err := req.MultipartReader()
for {
    part, err_part := read_form.NextPart()
    if err_part == io.EOF {
        break
    }
    if part.FormName() == "file" {
        //do something with files
    } else if part.FormName() == "delete" {
        //curata_folder()
        log.Println("delete is: ", part.Header.Get("delete"))
    }
}

How do i get the value of "delete"?

part.Header.Get("delete"))

it's not working

  • 写回答

2条回答 默认 最新

  • douaoj0994 2015-03-09 11:08
    关注

    You can probably content yourself by using the request.ParseMultipartForm method, then use the request.FormValue to get values as usual. Note that you also have the request.MultipartForm to get access to your files.

    Example:

    func(w http.ResponseWriter, r *http.Request) {
        // Here the parameter is the size of the form data that should
        // be loaded in memory, the remaining being put in temporary
        // files
        r.ParseMultipartForm(0)
    
        fmt.Println(r.FormValue("delete"))
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格