swagger-node-express:如何从swagger-ui上传文件?

看到这个Q&A,但没有相同的结果作为OP 如何张贴文件在大招?

在我的swagger-node-express API中使用这个规范

exports.saveFile = { 'spec' : { "description" : "Saves a file to filesystem", "path" : "/uploads/file", "notes" : "", "summary" : "POST a file to storage", "method" : "POST", /* "supportedContentTypes" : [ 'multipart/form-data' ], */ "produces":[ "application/json" ], "consumes":[ "multipart/form-data" ], "params" : [{ "name": "File", "description": "The file to upload.", "paramType": "body", "required": true, "allowMultiple": false, "dataType": "file" } ], "responseClass" : "ArbitraryJson", "errorResponses" : [ errors.invalid('file') ], "nickname" : "saveFile" }, 'action' : function(req, res) { res.send('{"msg":"success", "file path": "' + req.files.file.path + '"}'); } }; 

当我通过curl发布时, curl -v -F file=@scrot.png http://127.0.0.1:3000/uploads/file一切正常。 当我通过swagger-ui发布(v 2.0.2)失败。 我在这两种情况下都使用了代理,而且swagger-ui没有指定内容types,也没有传递数据。

通过curl简化原始文章(使用上面的命令)

 POST http://127.0.0.1:3000/uploads/file HTTP/1.1 User-Agent: curl/7.27.0 Host: 127.0.0.1:3000 Accept: */* Content-Length: 43947 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------9af70f8a272c ------------------------------9af70f8a272c Content-Disposition: form-data; name="file"; filename="scrot.png" Content-Type: application/octet-stream ... ------------------------------9af70f8a272c-- 

通过swagger-ui简化原始文章

 POST http://127.0.0.1:3000/uploads/file HTTP/1.1 Host: 127.0.0.1:3000 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0 Accept: application/json Accept-Language: en-US,en;q=0.5 Referer: http://127.0.0.1:3000/docs/ Content-Length: 0 Content-Type: text/plain; charset=UTF-8 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache 

我应该如何configuration我的路线/规格,所以swagger-ui会正确发布?

       

网上收集的解决方案 "swagger-node-express:如何从swagger-ui上传文件?"