Issue Embedding S3 Presigned URL in ngx-doc-viewer (Google Docs Viewer / Microsoft Office...

Discussão em 'Angular' iniciado por Heisenberg, Fevereiro 7, 2025.

  1. Heisenberg

    Heisenberg Guest

    I'm trying to preview documents (.docx, .xlsx, .pdf) in my Angular application using ngx-doc-viewer. The documents are stored in Amazon S3, so I generate a presigned S3 URL and pass it to the viewer.

    Here's how I'm using ngx-doc-viewer:

    <ngx-doc-viewer
    ="googleDocsUrl" viewer="google" ...s3-private-documents-and-presigned-urls']blog post that faced the same issue. It suggested that the problem occurs because the presigned S3 URL contains query parameters (?, &, =), which interfere with the Google Docs Viewer. Based on that, I tried the following solutions:

    1. Encoding the URL with encodeURIComponent

    const encodedUrl = encodeURIComponent(amazonPresignedUrl);
    this.googleDocsUrl = `https://docs.google.com/viewer?url=${encodedUrl}&embedded=true`;


    No luck, still getting "No Preview Available".

    1. Using encodeURI instead of encodeURIComponent

    const encodedUrl = encodeURI(amazonPresignedUrl);
    this.googleDocsUrl = `https://docs.google.com/viewer?url=${encodedUrl}&embedded=true`;


    Did not work either.

    1. Testing Direct Access

    The presigned S3 URL works fine when opened directly in a new tab, so it's not an S3 permission issue.

    1. Trying Microsoft Office Viewer Instead

    <ngx-doc-viewer
    ="officeViewerUrl" viewer="micros...ogle-docs-viewer-microso"]Continue reading...

Compartilhe esta Página