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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应