如何组织完整的七牛上传请求报文?

我用postman调试七牛上传接口时出现

{
"error": "invalid multipart format: multipart: NextPart: EOF"
}

这是怎么回事?

阅读 6.6k
2 个回答

我测试的时候都是使用curl 测试 ,使用 -F 指定form字段, 直传文件需要以下几个字段
参考这里
http://developer.qiniu.com/docs/v6/api/reference/up/upload.html
命令如下

curl -v -F 'key=1111' -F 'token=g8D_Ledyo2iocGucAXSMEJqPFDly70AaHKCpQznb:5-oM4A7Hv8DTS1DVwBjE56x85sw=:eyJzY29wZSI6Inpob3VjaHVhbmciLCJkZWFkbGluZSI6MTQyNjc0NjY0Mn0=' -F 'file=@/Users/qn/qbox/devtools/bin/httpServer' upload.qiniu.com
* Rebuilt URL to: upload.qiniu.com/
* Hostname was NOT found in DNS cache
* Trying 183.136.139.10...
* Connected to upload.qiniu.com (183.136.139.10) port 80 (#0)

POST / HTTP/1.1
User-Agent: curl/7.37.1
Host: upload.qiniu.com
Accept: /
Content-Length: 5795710
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------7aa9c49f35d7c3fc

< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
* Server nginx/1.4.4 is not blacklisted
< Server: nginx/1.4.4
< Date: Thu, 19 Mar 2015 05:52:39 GMT
< Content-Type: application/json
< Content-Length: 52
< Connection: keep-alive
< Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size
< Access-Control-Allow-Methods: OPTIONS, HEAD, POST
< Access-Control-Allow-Origin: *
< Access-Control-Max-Age: 2592000
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< X-Content-Type-Options: nosniff
< X-Log: s.ph;s.put.tw:5;s.put.tr:35;s.put.tw:8;s.put.tr:27;s.ph;s.put.tw:8;s.put.tr:23;s.ph;PFDS:77;PFDS:78;PFDS:79;rs12_2.sel/not found;rs11_2.sel/not found;rdb.g/no such key;DBD/404;DBG/404;v4.sel:1/Document not found;rs12_2.ins;qtbl.ins:3;mc.s;RS:4;rs.put:5;rs-upload.putFile:85;UP:147
< X-Reqid: eXMAANrPNJtv0MwT
<
* Connection #0 to host upload.qiniu.com left intact
{"hash":"lncC8mhuIxXLwLerWomKOLy3LREs","key":"1111"}

新手上路,请多包涵

在 Content-Disposition: form-data; name="file"; filename="xxxx" ...部分,
name必须为“file”,我开始使用的“file1”,怎么都不行,后来抓包与七牛的测试例子做比较,就这里不一样了,改成“file”终于返回200了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进