[英]Convert Pdf response from API Call to Blob and generate Blob Url
I am trying to convert the response to blob and then generate url to access that.我正在尝试将响应转换为 blob,然后生成 url 来访问它。 The response from the get request is Pdf.
获取请求的响应是 Pdf。
Here's what I am doing.这就是我正在做的事情。
this.$http.get<string>(
invoicePath
).then((response:any)=> {
console.log("CREATING A BLOB")
console.log("RESPONSE BLOB: ", response.data);
const blob:any = new Blob([response], { type: 'application/pdf; charset=utf-8' });
console.log("RESPONSE BLOB: ", blob);
const url= window.URL.createObjectURL(blob);
// window.open(url);
return url
//window.location.href = response.url;
})
The url returned gives me the below error message.返回的 url 给了我以下错误消息。
We have to convert the response to ArrayBuffer first.我们必须首先将响应转换为 ArrayBuffer。
this.$http.get<string>(
invoicePath, {responseType:'arraybuffer'}
).then((response:any)=> {
console.log("CREATING A BLOB")
console.log("RESPONSE BLOB: ", response.data);
const blob:any = new Blob([response.data], { type: 'application/pdf; charset=utf-8' });
console.log("RESPONSE BLOB: ", blob);
const url= window.URL.createObjectURL(blob);
// window.open(url);
return url
//window.location.href = response.url;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.