这是我用于返回带有多个图像的PDF的API。现在,当我使用url调用它时,它完美地下载了带有图像的PDF。例如,两个页面的图像。Blob和WebAPI的角度FileSaver。下载的PDF为空白。但API网址返回带有内容的PDF
[HttpGet]
public async Task<IHttpActionResult> Download(Guid customDocId)
{
byte[] responseContent = await Task.FromResult(FileNetApiClientFactory.Get(customDocId).DownloadDocument(customDocId, "pdf", true));
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(responseContent),
StatusCode = HttpStatusCode.OK,
};
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = string.Concat(customDocId.ToString(), ".pdf") };
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return ResponseMessage(response);
}
现在来自angular我使用blob和FileSaver
来保存PDF。所以当我下载它。然后它只返回两页,但没有内容。但它显示页面1和页面2,但它们是空白的。
这里是我的角度代码:
//saveAs method is from FileSaver.js
vm.download = function() {
documentService.download($scope.customDocumentId).then(function (fileData) {
var blob = new Blob([fileData], { type: 'application/pdf' });
saveAs(blob, $scope.customDocumentId + ".pdf");
}).catch(function() {
});
}
,服务:
function _download(customDocumentId) {
return Restangular
.one('customdocument', customDocumentId).one('download')
.get(null, { responseType: 'arraybuffer' });
}
有没有人有任何想法,为什么它返回空白页时FileSaver保存,而直接下载对所有内容都完美无瑕。
didnt解决我的问题。它仍然返回PDF空白页:( – Joy
也在我的应用程序FileSaver.saveAs()不存在。它唯一的saveAs()不知道为什么。我使用FileSaver.min.js – Joy