2013-11-21 2 views
7

이 Q &를 보았다하지만 예상대로 curl -v -F [email protected] http://127.0.0.1:3000/uploads/file 모든 작품, 컬를 통해 게시 할 때 내 자신감 노드-명시 APIswagger-node-express : swagger-ui에서 파일을 업로드하는 방법은 무엇입니까?

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 + '"}'); 

    } 
}; 

이 스펙을 사용하여 OP How to post files in swagger?

으로 같은 결과를하지 않았다. swagger-ui (v 2.0.2)를 통해 게시하면 실패합니다. 나는 두 가지 상황에서 프록시를 사용했고, swagger-ui는 content-type을 지정하지 않고 데이터를 전달하지도 않습니다. 컬를 통해

단축 원시 포스트

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-- 

는 자신감-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 

내 경로/사양을 구성해야합니다 어떻게 자신감-△ ▽를 게시 할 예정 있도록 바르게?

+0

이 문제를 해결 했습니까? 같은 일에 뛰어 들다. – clay

+0

"body"가 아닌 "paramType"을 "form"으로 설정해보십시오. – Ron

답변

0

정상적인 양식 값으로 POST를 수행 할 수있는 동일한 문제가 있었지만 파일을 전달할 때 데이터가 없습니다. 저에게있어서 문제는 익스프레스 4를 사용하고 멀 테터를 설치 및 설정하지 않았기 때문입니다. 자세한 내용은 다음을 참조하십시오.

https://github.com/swagger-api/swagger-node-express/issues/202

관련 문제