dsj2222222 2017-04-20 19:01
浏览 371
已采纳

MIME ParseMediaType在多部分边界上失败

I am a Golang api that accept multipart/form-data requests. For some clients, however, it fails to parse the form because it doesn't like the boundary being used by the client.

The header from the client is:

Content-Type:[multipart/form-data; boundary================1648430772==]

I've narrowed this down to the ParseMediaType function in the mime package.

If I call:

bad := "multipart/form-data; boundary=1650458473"
d, params, err := mime.ParseMediaType(v)
if err != nil {
    fmt.Println("err", err)
}
fmt.Println(d, params)

I get the err: mime: invalid media parameter.

Note that if I do this call with

multipart/form-data; boundary=3fc88aad6d1341a4921fd5ac9efe607c

it succeeds no problem.

According to the https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html spec, it looks to me like these are all valid characters for a boundary.

Is this a bug in the Go mime library? Or is this really an invalid boundary?

  • 写回答

2条回答 默认 最新

  • dsk49208 2017-04-20 20:12
    关注

    The rfc you linked to contains BNF for the boundary and multipart body, it does not contain the BNF for the Content-Type Header Field. So while = in boundary is just fine it's not fine in the parameter value of the Content-Type header. At least not unquoted.

    So to fix your first example change the Content-Type to this:

    multipart/form-data; boundary="===============1648430772=="

    https://play.golang.org/p/3Iuk_ACZaQ

    Your second example multipart/form-data; boundary=1650458473 seems to work fine.

    https://play.golang.org/p/xJWwBa_QiP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作