У меня есть метод web api, который возвращает HttpResponseMessage
, содержащий файл PDF. Метод выглядит примерно так:
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read));
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = fileName;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
Когда я вызываю этот api из клиента (который написан в angularJS), Internet Download Manager автоматически ловит файл PDF и хочет его загрузить. И поскольку у меня есть план безопасности для моего проекта, IDM автоматически запрашивает имя пользователя и пароль. Кто-нибудь имеет представление о том, как я должен программно отключать IDM, чтобы поймать PDF файл?
Обновление: Здесь мой код angularJS:
$http.post(url, { transactionId: txId }
, {responseType: 'arraybuffer'})
.success(function (response) {
var reader = new FileReader();
var file = new Blob([response.data], {type: 'application/pdf'});
reader.onload = function (e) {
var printElem = angular.element('#printPdfLink');
printElem.attr('target', '_blank');
printElem.attr('href', reader.result);
printElem.attr('ng-click', '');
};
reader.readAsDataURL(file);
})
.error(function (error) {});