cyntler / react-doc-viewer

File viewer for React.
https://cyntler.github.io/react-doc-viewer
Apache License 2.0
392 stars 127 forks source link

Iam not able to load from aws urls #219

Closed SidWML closed 10 months ago

SidWML commented 10 months ago

https://static-sq-chat.s3.amazonaws.com/uploads/98820cea/D_Strange-Girl_Meets_Boy_Penguin_Readers-1-min.pdf?AWSAccessKeyId=adghakdehaoyKLKHSnKLhljKLDHklabdx&Signature=fsdfDsfsfsfsfsfD&Expires=1704870237 <DocViewer documents={[{uri:'/movies100.pdf'}]} pluginRenderers={DocViewerRenderers} prefetchMethod="GET" /> Iam not able to load from the above path but files from local are working fine

roy-andri commented 10 months ago

Have you set up the cors on your AWS bucket?

https://repost.aws/knowledge-center/s3-configure-cors

[
    {
        "AllowedHeaders": [
            "Authorization"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*" <-- Put your whitelist URL here
        ],
        "ExposeHeaders": [
            "Access-Control-Allow-Origin"
        ]
    }
]

Also don't forget to put fileType

<DocViewer
        documents={[
          {
            uri: url,
            fileType: "pdf",
          },
        ]}
</DocViewer>
SidWML commented 10 months ago

<DocViewer documents={[{uri:'/dum.doc', fileType: "doc",}]} pluginRenderers={DocViewerRenderers} /> but local doc files are not getting show there is an error doc

SidWML commented 10 months ago

@roy-andri Thanks but I have a question if I paste the urls in the browser Iam able to download the pdfs but in the app it got stuck in a infinte loop loader image

roy-andri commented 10 months ago

Thanks but I have a question if I paste the urls in the browser Iam able to download the pdfs but in the app it got stuck in a infinte loop loader

For this one, have you put the fileType? Can you share your network tab while requesting the document from AWS? Is it getting 200?

SidWML commented 10 months ago

@roy-andri Here it is image

roy-andri commented 10 months ago

I guess there is something wrong with your CORS configuration, I will facing the same issue if I remove the CORS configuration from my AWS bucket.

SidWML commented 10 months ago

@roy-andri Thank you very much

SidWML commented 10 months ago

Hi @roy-andri thanks for the solution above its working for pdf but its not working for doc and docx image

roy-andri commented 10 months ago

How do you handle the rendering process? Can you share your code, maybe there is something wrong with your rendering.

https://support.mozilla.org/en-US/kb/xframe-neterror-page

It's working fine on my Firefox

Screenshot 2024-01-12 at 9 45 37 PM
SidWML commented 10 months ago

Hi @roy-andri thanks for the reply i appreciate this is the code const docs = [{uri:docURL ,fileType:'doc'}]
<DocViewer className='w-[60%]' prefetchMethod="GET" documents={docs} pluginRenderers={ DocViewerRenderers } />

roy-andri commented 10 months ago

Are you facing this error on the local or after you deploy the website? can you make sure the file type is doc, not docx?

Here is how I call this library, with this code, I can preview 3 different file types (doc/x,pdf,txt)

      <DocViewer
        documents={[
          {
            uri: url,
            fileType: extension,
          },
        ]}
        config={{
          header: { disableHeader: true },
          pdfVerticalScrollByDefault: true,
        }}
        prefetchMethod="GET"
      />
SidWML commented 10 months ago

@roy-andri and this is what I am getting when I open it in mirrosoft edge image

SidWML commented 10 months ago

@roy-andri its in local what is this extension the file I have to display 3 types pdf,doc and docx

roy-andri commented 10 months ago

what is this extension the file I have to display 3 types pdf,doc and docx

It's depends on your file, if your file is docx then the fileType should docx as well

SidWML commented 10 months ago

@roy-andri image this is what in the network headers

SidWML commented 10 months ago

@roy-andri image

roy-andri commented 10 months ago

Have you tried using incognito tab?

SidWML commented 10 months ago

no @roy-andri its not working what is the version you are using

roy-andri commented 10 months ago

"@cyntler/react-doc-viewer": "^1.14.1"

SidWML commented 10 months ago

@roy-andri Iam using the same package thanks for the help

roy-andri commented 10 months ago

It seems your file URL is empty @SidWML

Screenshot 2024-01-12 at 10 43 31 PM

I also facing same issue if I try set the file URL using empty string.

Screenshot 2024-01-12 at 10 43 03 PM Screenshot 2024-01-12 at 10 42 34 PM
roy-andri commented 10 months ago

It should contain your file URL

Screenshot 2024-01-12 at 10 46 49 PM
SidWML commented 10 months ago

@roy-andri thanks man I have wrote a condition where Iam storing the docURL I missed to check .Thank you once again Its working