douyanxing6054 2013-09-05 04:53 采纳率: 0%
浏览 80
已采纳

当ErrNotMultipart时ParseMultipartForm()返回nil

http://golang.org/src/pkg/net/http/request.go

Why it returns to nil when ErrNotMultipart?

mr, err := r.multipartReader()
767     if err == ErrNotMultipart {
768         return nil 
769     } else if err != nil {
770         return err
771     }

In my case, I had a typo from my header

multipart/form-data, boundary=xxxx

The above should have a semi-colon instead of a comma. Now, I was tracing this for hours, because I thought ParseMultipartForm processed the data successfully.

There could be a strong reason why it was forced to nil, judging from the code.

(I posted this same question at golang-nuts group, but when I posted a reply to the first collaborator, my reply was not posted successfully. So, I think stackoverflow is a better tool for posting this question)

  • 写回答

1条回答 默认 最新

  • dt3999 2013-09-05 07:40
    关注

    I think you did it right in the first place to write to golang-nuts instead of here.

    This does indeed look like a bug and should therefore be discussed in the issue tracker or on golang nuts. Note that golang-nuts is moderated and therefore your posts will not appear immediately (which might have happened to you).

    As a workaround you can use Request.MultipartReader and do the reading by yourself (copied from ParseMultipartForm):

    mr, err := r.multipartReader() // don't forget to handle err
    f, err := mr.ReadForm(maxMemory) // don't forget to handle err
    
    for k, v := range f.Value {
        r.Form[k] = append(r.Form[k], v...)
    }
    r.MultipartForm = f
    

    Judging from what I can deduce from the code history, this was simply overlooked. The changes are from 2011 and the review for the particular lines of code can be found here. The tests don't seem to cover this particular parse error. The review even says:

    On 2011/04/28 00:08:40, bradfitz wrote: I think you'll always return an error here for multipart forms. See comment above.

    Fixed.

    Which was done for almost all errors but this one. So, as I said, I think it is a bug.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗