gpt4 book ai didi

Angular 4 : Convert Response from API to PDF

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:06 24 4
gpt4 key购买 nike

enter image description here

大家好,我尝试从API转换响应时遇到问题,我收到错误

The request body isn't either a blob or an array buffer

这是我的代码

应用程序服务.ts

downloadPDF(id_booking): any {
let headers = new Headers();
this.createAuthorizationHeader(headers);
return this.http.post('https://localhost:1210/v1/user/booking/eticket/'+id_booking, {responseType: ResponseContentType.Blob}, {headers: headers}).map(
(res) => {
console.log(res)
return new Blob([res.blob()], { type: 'application/pdf' })
})
}

pdf.component.ts

this.appService.downloadPDF(booking._id).subscribe(
(res) => {
saveAs(res, "myPDF.pdf");
var fileURL = URL.createObjectURL(res);
window.open(fileURL);
}

最佳答案

您的后端当前正在发送一个字符串。

假设您使用的是 express,而不是

res.send(arr)

你应该使用

res.send(buffer);

这将确保发送二进制数据

关于 Angular 4 : Convert Response from API to PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53202658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com