我一直在尝试显示pdf文件,我从$http.post响应中获取blob .例如,pdf必须在应用程序中显示<embed src>.
我遇到了几个堆栈帖子,但不知怎的,我的例子似乎不起作用.
JS:
根据这份文件,我继续尝试......
$http.post('/postUrlHere',{myParams}).success(function (response) {
var file = new Blob([response], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
$scope.content = fileURL;
});
Run Code Online (Sandbox Code Playgroud)
根据我的理解,fileURL创建一个临时URL,博客可以将其用作参考.
HTML:
<embed src="{{content}}" width="200" height="200"></embed>
Run Code Online (Sandbox Code Playgroud)
我不知道如何在Angular中处理这个问题,理想的情况是(1)将它分配给范围,(2) '准备/重建'blob到pdf (3)将其传递给HTML使用<embed>因为我想要在应用程序中显示它.
我已经研究了一天以上但不知何故我似乎无法理解它在Angular中是如何工作的......让我们假设那里的pdf查看器库没有选项.
我在Angular JS中创建了一个应用程序,用于通过$ http帖子下载Excel工作簿.
在下面的代码中,我以JSON的形式传递信息,并通过角度$ http帖子将其发送到服务器REST Web服务(java).Web服务使用JSON中的信息并生成Excel工作簿.在$ http post的成功主体内的响应中,我在该数据变量中获取二进制数据,但不知道如何转换它并下载为Excel文件.
谁能告诉我一些解决方案,将二进制文件转换为Excel文件并下载?
我的代码如下:
$http({
url: 'myweb.com/myrestService',
method: "POST",
data: json, //this is your json data string
headers: {
'Content-type': 'application/json'
}
}).success(function (data, status, headers, config) {
// Here i'm getting excel sheet binary datas in 'data'
}).error(function (data, status, headers, config) {
});
Run Code Online (Sandbox Code Playgroud)