【问题标题】:Export to PDF by using Rest API(send to file) in my react project is getting blank PDF在我的反应项目中使用 Rest API(发送到文件)导出到 PDF 是空白 PDF
【发布时间】:2021-04-23 16:22:43
【问题描述】:

API 返回的 PDF 数据示例如下 -


以下是我用来下载 PDF 的 JavaScript 代码,我尝试了很多解决方案,但都没有奏效。

常量 reportPdfDoc = 等待 axiosBIInstance.get( `https://api.powerbi.com/v1.0/myorg/reports/${config.reportId}/exports/${exportID?.data?.id}/file`, { 标题:{ 授权:'Bearer' + accessToken, responseType: 'arraybuffer',// 我也使用过 blob,但结果相同 }, }, ); if (reportPdfDoc?.status === 200) { const blob = new Blob([reportPdfDoc.data], { 类型:'应用程序/pdf', }); 常量计算文件名 = `${exportStatus?.data?.reportName}.pdf`; const a = document.createElement('a'); a.href = window.URL.createObjectURL(blob); a.download = 计算文件名; document.body.appendChild(a); a.点击(); document.body.removeChild(a);

【问题讨论】:

  • 我遇到了问题,responseType 属性应该在 axios 调用的标头之外。比如 - const reportPdfDoc = await axiosBIInstance.get(https://api.powerbi.com/v1.0/myorg/reports/${config.reportId}/exports/${exportID?.data?.id}/file, { headers: { Authorization: 'Bearer' + accessToken, }, responseType: 'blob', }, );

标签: javascript reactjs pdf powerbi powerbi-embedded


【解决方案1】:

我尝试了上面发布的解决方案,它对我有用。我在下面重新发布它。

我遇到了问题,responseType 属性应该在 axios 调用的标头之外。喜欢-

const reportPdfDoc = await axiosBIInstance.get( https://api.powerbi.com/v1.0/myorg/reports/${config.reportId}/exports/${exportID?.data?.id}/file, { headers: { Authorization: 'Bearer ' + accessToken, }, responseType: 'blob', }, ); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多