gerhardsletten / react-reader

An ePub-reader for React, powered by Epub.js
https://react-reader.metabits.no
Apache License 2.0
721 stars 132 forks source link

Can't read s3 presigned urls. #151

Closed romikforest closed 1 year ago

romikforest commented 1 year ago

Is there a solution for the s3 presigned urls?

gerhardsletten commented 1 year ago

@romikforest Is this related to gerhardsletten/react-reader#handling-missing-mime-types-on-server

romikforest commented 1 year ago

Hi. No, it's about the additional query parameters that s3 presigned urls have. I've found that the reader accepts a blob for the url parameter. So as a workaround I download the file and then pass the blob to the reader.

gerhardsletten commented 1 year ago

@romikforest Did you see this old issue: #49

romikforest commented 1 year ago

No. I haven't seen. It works that way too.

But actually I don't sure what it has with mime. S3 returns application/epub+zip for the file (sets it automatically on upload). The head requests aren't working with the urls. Somebody can get the mime with zero range GET that has the same effect as HEAD request:

        const reponse = await fetch(url, {
            headers: {range: 'bytes=0-0'}
        });
        const mime = reponse.headers.get('Content-Type');
        console.log(mime);
gerhardsletten commented 1 year ago

I think you would need it if the path url do not contain ".epub" at the end. This is related to inner workings of epubjs

romikforest commented 1 year ago

Ok. Thank you a lot for your support.

Just as a remark. As I said some one can also use blobs:

        const blob = await fetch(s3url).then(r => r.blob());
        setUrl(blob)