【问题标题】:Displaying Pdf from azure blob storage显示来自 azure blob 存储的 Pdf
【发布时间】:2018-11-08 21:09:12
【问题描述】:

我正在尝试在我的页面上显示一个 pdf 文件。 pdf 文件位于 azure 上的 blob 中。我从服务器获取到 blob 本身的链接,这样我就可以直接从存储中获取文件,而不是通过服务器传递它。

我设置了共享访问签名(SAS 密钥),因为容器受到保护。

因为我使用的是 angular 5,所以我需要清理我正在做的网址。

 this.http.get(baseUrl + 'api/download/fileuri?sheetId=' + this.sheetId, { responseType: 'text' }).subscribe(result => {
        this.url = result.toString();            
        this.sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
        console.log(this.sanitizedUrl);
    }, error => console.error(error));

然后我将它放在一个对象中,但我要么只得到一个白页,要么得到以下错误。

<object [data]="sanitizedUrl" type="application/pdf" style="width:100%; height:100vh"></object>

我在 azure 中设置了以下内容:

最奇怪的部分是:我可以抓取该文件,但只需输入该链接,它就会开始下载它。但是当我尝试从对象访问它时,它会抛出该错误。所以链接是正确的并且有效。只是每当我尝试从页面内访问它时..

【问题讨论】:

  • 您需要为您的 blob 启用 CORS
  • 我做了,最后一张图片是存储帐户 CORS。我通过输入 * 来允许所有流量通过,以确保不会阻止它进行测试

标签: angular azure azure-storage


【解决方案1】:

我建议您下载 Microsoft Azure Storage Explorer。在其中,您可以为特定资源设置 CORS 策略。希望能解决你的问题。

【讨论】:

    猜你喜欢
    • 2020-07-22
    • 1970-01-01
    • 2023-04-08
    • 2022-01-19
    • 2018-06-20
    • 2015-08-13
    • 2023-01-03
    • 2016-11-18
    • 2020-12-03
    相关资源
    最近更新 更多