sah diesen q & ein, aber hatte keine gleichen Ergebnisse wie OP How to post files in swagger?swagger-node-express: Wie kann ich eine Datei von swagger-ui hochladen?
diese spec Verwendung in meiner Prahlerei-Knoten-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 + '"}');
}
};
Wenn ich über curl Post, curl -v -F [email protected] http://127.0.0.1:3000/uploads/file
alles wie erwartet funktioniert. Wenn ich via swagger-ui (v 2.0.2) poste, schlägt es fehl. Ich habe einen Proxy in beiden Situationen verwendet und der swagger-ui gibt weder den Inhaltstyp an, noch gibt er die Daten weiter.
Verkürzte roh Beitrag über curl (mit dem Befehl oben)
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--
Verkürzte roh Beitrag über Prahlerei-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
Wie soll ich meine Route/spec so konfigurieren, dass die Prahlerei-ui werde nach korrekt?
Haben Sie jemals dieses Problem lösen? In dieselbe Sache hineinlaufen. – clay
Versuchen Sie, "paramType" auf "form" und nicht auf "body" zu setzen. – Ron