diff --git a/example/example.js b/example/example.js index 90aa4ede..924a864a 100644 --- a/example/example.js +++ b/example/example.js @@ -72,6 +72,7 @@ function postUser() { return; } * @apiDescription This function has same errors like POST /user, but errors not defined again, they were included with "apiErrorStructure" * * @apiParam {String} name Name of the User. + * @apiParam {File} avatar Upload avatar. * * @apiUse CreateUserError */ diff --git a/template/index.html b/template/index.html index 668f6061..832daa88 100644 --- a/template/index.html +++ b/template/index.html @@ -291,7 +291,7 @@

- +
{{{type}}}
diff --git a/template/utils/handlebars_helper.js b/template/utils/handlebars_helper.js index a86733f5..90e902cb 100644 --- a/template/utils/handlebars_helper.js +++ b/template/utils/handlebars_helper.js @@ -21,6 +21,16 @@ define([ return text; }); + /** + * set paramater type. + */ + Handlebars.registerHelper("setInputType", function(text) { + if (text === "File") { + return "file"; + } + return "text"; + }); + /** * start/stop timer for simple performance check. */ diff --git a/template/utils/send_sample_request.js b/template/utils/send_sample_request.js index 5c99b74c..ab75e675 100755 --- a/template/utils/send_sample_request.js +++ b/template/utils/send_sample_request.js @@ -53,8 +53,7 @@ define([ // create JSON dictionary of parameters var param = {}; var paramType = {}; - var bodyFormData = {}; - var bodyFormDataType = {}; + var bodyFormData = new FormData(); var bodyJson = ''; $root.find(".sample-request-param:checked").each(function(i, element) { var group = $(element).data("sample-request-param-group-id"); @@ -79,8 +78,10 @@ define([ } if (contentType == "body-form-data"){ header['Content-Type'] = 'multipart/form-data' - bodyFormData[key] = value; - bodyFormDataType[key] = $(element).next().text(); + if (element.type == "file") { + value = element.files[0]; + } + bodyFormData.append(key,value); }else { param[key] = value; paramType[key] = $(element).next().text(); @@ -134,6 +135,11 @@ define([ error : displayError }; + if(header['Content-Type'] == 'multipart/form-data'){ + delete ajaxRequest.headers['Content-Type']; + ajaxRequest.contentType=false; + ajaxRequest.processData=false; + } $.ajax(ajaxRequest);