diff --git a/src/main/coffeescript/view/OperationView.coffee b/src/main/coffeescript/view/OperationView.coffee index 0c211f17..4df219f5 100644 --- a/src/main/coffeescript/view/OperationView.coffee +++ b/src/main/coffeescript/view/OperationView.coffee @@ -52,6 +52,23 @@ class OperationView extends Backbone.View if(o.value? && jQuery.trim(o.value).length > 0) map[o.name] = o.value + isFileUpload = $('input[type~="file"]').size != 0 + + if isFileUpload + # requires HTML5 compatible browser + bodyParam = new FormData() + + # add params + for param in @model.parameters + if param.paramType is 'body' + bodyParam.append(param.name, map[param.name]) + + # add files + $.each $('input[type~="file"]'), (i, el) -> + bodyParam.append($(el).attr('name'), el.files[0]) + + console.log(bodyParam) + else bodyParam = null for param in @model.parameters if param.paramType is 'body' @@ -79,6 +96,7 @@ class OperationView extends Backbone.View headers: headerParams data: bodyParam dataType: 'json' + processData: false error: (xhr, textStatus, error) => @showErrorStatus(xhr, textStatus, error) success: (data) => @@ -87,7 +105,7 @@ class OperationView extends Backbone.View @showCompleteStatus(data) obj.contentType = "application/json" if (obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch") - + obj.contentType = false if isFileUpload jQuery.ajax(obj) false # $.getJSON(invocationUrl, (r) => @showResponse(r)).complete((r) => @showCompleteStatus(r)).error (r) => @showErrorStatus(r) diff --git a/src/main/coffeescript/view/ParameterView.coffee b/src/main/coffeescript/view/ParameterView.coffee index c6c5dd55..a7c4361a 100644 --- a/src/main/coffeescript/view/ParameterView.coffee +++ b/src/main/coffeescript/view/ParameterView.coffee @@ -3,6 +3,7 @@ class ParameterView extends Backbone.View render: -> @model.isBody = true if @model.paramType == 'body' + @model.isFile = true if @model.dataType == 'file' template = @template() $(@el).html(template(@model)) diff --git a/src/main/template/param.handlebars b/src/main/template/param.handlebars index 628f3577..bd311a0e 100644 --- a/src/main/template/param.handlebars +++ b/src/main/template/param.handlebars @@ -1,13 +1,16 @@ {{name}} - + {{#if isBody}} - {{#if defaultValue}} - + {{#if isFile}} + {{else}} - + {{#if defaultValue}} + + {{else}} + + {{/if}} {{/if}} - {{else}} {{#if defaultValue}} diff --git a/src/main/template/param_required.handlebars b/src/main/template/param_required.handlebars index 105e7064..2a4a31f4 100644 --- a/src/main/template/param_required.handlebars +++ b/src/main/template/param_required.handlebars @@ -1,21 +1,28 @@ {{name}} {{#if isBody}} - {{#if defaultValue}} - + {{#if isFile}} + {{else}} - + {{#if defaultValue}} + + {{else}} + + {{/if}} {{/if}} - {{else}} - {{#if defaultValue}} - + {{#if isFile}} + {{else}} - + {{#if defaultValue}} + + {{else}} + + {{/if}} {{/if}} {{/if}} {{{description}}} -{{{signature}}} \ No newline at end of file +{{{signature}}}