Add support for downloading via Blob

This commit is contained in:
Mohsen Azimi
2015-03-26 13:06:33 -07:00
parent 6b8f6e2827
commit c157fe41c1
3 changed files with 44 additions and 6 deletions

19
dist/swagger-ui.js vendored
View File

@@ -21343,6 +21343,25 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
headers['content-disposition'].test(/attachment/) ||
headers['Content-Description'].test(/File Transfer/) ||
headers['content-description'].test(/File Transfer/)) {
if ('Blob' in window) {
var type = contentType || 'text/html';
var blob = new Blob([content], {type: type});
var a = document.createElement('a');
var href = window.URL.createObjectURL(blob);
var fileName = response.url.substr(response.url.lastIndexOf('/') + 1);
var download = [type, fileName, href].join(':');
a.setAttribute('href', href);
a.setAttribute('download', download);
pre = $('<div/>').append(a);
} else {
pre = $('<pre class="json" />').append('Download headers detected but your browser does not support downloading binary via XHR (Blob).');
}
// Location header based redirect download
} else if(headers['location'] || headers['Location']) {
window.location = response.url;
// Anything else (CORS)