Browse Source

blob handling, render download link for application/octet-stream

bubble
Tony Tam 7 years ago
parent
commit
65d81745ed
1 changed files with 14 additions and 1 deletions
  1. +14
    -1
      src/main/javascript/view/OperationView.js

+ 14
- 1
src/main/javascript/view/OperationView.js View File

@@ -672,6 +672,17 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
contentType = contentType.split(';')[0].trim(); contentType = contentType.split(';')[0].trim();
} }
} }
if(contentType) {
if(typeof content === 'string') {
var arrayBuffer = new ArrayBuffer(content.length);
var uint8Array = new Uint8Array(arrayBuffer);
for (var i = 0; i < content.length; i++) {
uint8Array[i] = content.charCodeAt(i);
}

content = new Blob([uint8Array], { type: contentType });
}
}
$('.response_body', $(this.el)).removeClass('json'); $('.response_body', $(this.el)).removeClass('json');
$('.response_body', $(this.el)).removeClass('xml'); $('.response_body', $(this.el)).removeClass('xml');


@@ -687,7 +698,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
pre = $('<pre class="json" />').append(code); pre = $('<pre class="json" />').append(code);


// JSON // JSON
} else if (headers['Content-Disposition'] && (/attachment/).test(headers['Content-Disposition']) ||
} else if (
contentType === 'application/octet-stream' ||
headers['Content-Disposition'] && (/attachment/).test(headers['Content-Disposition']) ||
headers['content-disposition'] && (/attachment/).test(headers['content-disposition']) || headers['content-disposition'] && (/attachment/).test(headers['content-disposition']) ||
headers['Content-Description'] && (/File Transfer/).test(headers['Content-Description']) || headers['Content-Description'] && (/File Transfer/).test(headers['Content-Description']) ||
headers['content-description'] && (/File Transfer/).test(headers['content-description'])) { headers['content-description'] && (/File Transfer/).test(headers['content-description'])) {


Loading…
Cancel
Save