[英]Convert Pdf response from API Call to Blob and generate Blob Url
我正在嘗試將響應轉換為 blob,然后生成 url 來訪問它。 獲取請求的響應是 Pdf。
這就是我正在做的事情。
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;
})
我們必須首先將響應轉換為 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.