Skip to content

Commit 65d8174

Browse files
committed
blob handling, render download link for application/octet-stream
1 parent 46fbae2 commit 65d8174

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/javascript/view/OperationView.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,17 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
672672
contentType = contentType.split(';')[0].trim();
673673
}
674674
}
675+
if(contentType) {
676+
if(typeof content === 'string') {
677+
var arrayBuffer = new ArrayBuffer(content.length);
678+
var uint8Array = new Uint8Array(arrayBuffer);
679+
for (var i = 0; i < content.length; i++) {
680+
uint8Array[i] = content.charCodeAt(i);
681+
}
682+
683+
content = new Blob([uint8Array], { type: contentType });
684+
}
685+
}
675686
$('.response_body', $(this.el)).removeClass('json');
676687
$('.response_body', $(this.el)).removeClass('xml');
677688

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

689700
// JSON
690-
} else if (headers['Content-Disposition'] && (/attachment/).test(headers['Content-Disposition']) ||
701+
} else if (
702+
contentType === 'application/octet-stream' ||
703+
headers['Content-Disposition'] && (/attachment/).test(headers['Content-Disposition']) ||
691704
headers['content-disposition'] && (/attachment/).test(headers['content-disposition']) ||
692705
headers['Content-Description'] && (/File Transfer/).test(headers['Content-Description']) ||
693706
headers['content-description'] && (/File Transfer/).test(headers['content-description'])) {

0 commit comments

Comments
 (0)