Getting "Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided" exception in swagger-ui-min.js file when i try to download a file using api method in swagger ui.
I tried with the following code but still getting the same issue
if (operation.operationId == "GetFile")
{
operation.produces = new[] { "application/octet-stream" };
operation.responses["200"].schema = new Schema { type = "file" };
}
Please help me to get this issue resolved.
Thanks.
Please help me to fix this issue.
I have also same issue. My API offers image by id and HttpResponseMessage has been created:
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(imageStream)
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = id + ".png"
};
but Chrome 55 gave me errors:
cannot parse JSON/YAML content
swagger-ui-min-js:14 Objectcache-control: "must-revalidate, max-age=18000, private"content-disposition: "attachment; filename=....png"content-length: "28945"content-type: "image/png"....
swagger-ui-min-js:14 Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
at showStatus (swagger-ui-min-js:14)
at showCompleteStatus (swagger-ui-min-js:14)
at response (swagger-ui-min-js:9)
at p (swagger-ui-min-js:7)
at t.on.response (swagger-ui-min-js:7)
at swagger-ui-min-js:7
at h.callback (swagger-ui-min-js:12)
at h.(swagger-ui-min-js:12)
at h.r.emit (swagger-ui-min-js:13)
at XMLHttpRequest.n.onreadystatechange (swagger-ui-min-js:13)
I am using Swashbuckle 5.5.3
I also noticed that swagger-ui-min-js contains following code:
if (r["Content-Disposition"] && /attachment/.test(r["Content-Disposition"]) ||
r["content-disposition"] && /attachment/.test(r["content-disposition"]) ||
r["Content-Description"] && /File Transfer/.test(r["Content-Description"]) ||
r["content-description"] && /File Transfer/.test(r["content-description"]))
if ("Blob"in window) {
var l = i || "text/html"
, u = document.createElement("a")
, c = window.URL.createObjectURL(n)
, p = e.url.substr(e.url.lastIndexOf("/") + 1)
, h = [l, p, c].join(":")
, f = r["content-disposition"] || r["Content-Disposition"];
if ("undefined" != typeof f) {
var d = /filename=([^;]*);?/.exec(f);
null !== d && d.length > 1 && (h = d[1])
}
and https://github.com/swagger-api/swagger-ui/blob/c04b81c51e5138dcc05e0ef33dce97a179eb99d3/src/main/javascript/view/OperationView.js may contain now fix for this issue:
if ('Blob' in window) {
var type = contentType || 'text/html';
var a = document.createElement('a');
var href;
if({}.toString.apply(content) === '[object Blob]') {
href = window.URL.createObjectURL(content);
}
else {
var binaryData = [];
binaryData.push(content);
href = window.URL.createObjectURL(new Blob(binaryData, {type: type}));
}
var fileName = response.url.substr(response.url.lastIndexOf('/') + 1);
var download = [type, fileName, href].join(':');
Is there coming any fixes in future?
I fix the problem this may, add { responseType: 'arraybuffer' } in the request of the service
getAgreement (context, childId) {
console.log('* Init getAgreement')
return new Promise((resolve, reject) => {
http.get(/medical/history/agreement/${childId}, *### { responseType: 'arraybuffer' })
.then((response) => {
resolve(response)
}).catch(err => {
errorHandler.checkError(context, err)
reject(err)
})
})
},
Most helpful comment
Is there coming any fixes in future?