futurepress / epubjs-rn

EpubJS React Native Example
Other
270 stars 150 forks source link

Not able to read epub as signed url from s3 #151

Open hsparihar-systango opened 5 years ago

hsparihar-systango commented 5 years ago

While I am using any open s3 url I am able to load and read epub like https://s3.amazonaws.com/epubjs/books/moby-dick.epub but when I use signed s3 URL getting an error while starting streamer i.e. this.streamer.start
{ [Error: failed to open zip file] framesToPop: 1, code: 'unzip_error', domain: 'SSZipArchiveErrorDomain', userInfo: { NSLocalizedDescription: 'failed to open zip file' },

signed URL like https://mydomain.s3.uss-east-235.amazonaws.com/epub/test.epub?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA5Q2POCDOH2PPQPV4%2F20190925%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20190925T104823Z&X-Amz-Expires=80000&X-Amz-Signature=e5b4cea0fc418edd432a3f02f0a8d2e20&X-Amz-SignedHeaders=host

port started successfully GCDWebServer started on port 8899 and reachable at http://localhost:8899/

Any help will be much appreciated.

goyalsushant commented 5 years ago

I am facing issues with the s3 signed URL. But I am getting 403 on /META-INF/container.xml

@hsparihar-systango have you find any solution for this?

hsparihar-systango commented 5 years ago

@goyalsushant in this module filename code is very sensitive for name and in signed URLs name is too long as it has additional pieces of information as well, so try with this code in Streamer.js file, replace existing code with this one

{ key: "filename", value: function filename(bookUrl) { var uri = new Uri(bookUrl); let finalFileName; if(uri.filename.indexOf("?") > -1) { finalFileName = uri.filename.split("?")[0].replace(".epub", ""); } else { finalFileName = uri.filename.replace(".epub", ""); } return finalFileName; } },

goyalsushant commented 5 years ago

@hsparihar-systango can you please mention the path for the file ?

hsparihar-systango commented 4 years ago

@goyalsushant file path /node_modules/epubjs-rn/components/Streamer.js

mananshah88 commented 4 years ago

@hsparihar-systango I faced a similar problem but in my case, it was the problem with bucket permission. Please check you S3 bucket policy, IAM (Role + policy).

@goyalsushant After solving the above problem, I faced the exact exception you got. For me, it is angular-epub-viewer which reads the CDN's presigned URL. Solution: The name of the file(uploaded on S3) must end with ".epub" extension.