Im using the filesaver js library for download files... i'm generating a endpoint with web api that returns my file from base64 but i don't know how to return base64 as Blob for download with filesaver....
- Im tried make differents responses types
- try to understand how to does it works the Blob data
public HttpResponseMessage GetFile(int id)
{
string mybase64file = GetBase64File(id)
byte[] bytes = Convert.FromBase64String(mybase64file );
MemoryStream ms = new MemoryStream(bytes);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(ms);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "someFileName.pdf";
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return result;
}
AngularJS service:
function download() {
var deferred = $q.defer()
$http.get('url', {
headers: {
'Content-type': 'application/octet-stream',
},
responseType: 'blob'
})
.success(function (response) {
saveAs(response, 'someName.pdf')
})
.error(function (err) {
deferred.reject(err)
})
return deferred.promise
}
When the angularjs service recieve to response, im call the "saveAs" function, but this generate the next error:
"angular.min.js:118 TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided."