0

I am working on a project where i have to display ebooks on my Laravel web app. I am using futurepress/epub.js to display epub file, epub.js displays files stored in local storage but when i store the files in s3 and use s3 urls it throws exception.

1. Uncaught ReferenceError: href is not defined is thrown when i use signed s3 url

Example: Uncaught ReferenceError: href is not defined is thrown in this line var Book = ePub("https://venkitest1.s3.us-east-2.amazonaws.com/contents/1/1/1/b6221779e85b87c620decc8028aaf8188c000b26.epub?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI6LL2FHRGEK5PCKA%2F20171208%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20171208T112812Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Signature=9a6ae022833c4a33495e164a6d5a9134b0444f821ea29d11c49b47b66f1727c8");

2. Failed to load https://venkitest1.s3.us-east-2.amazonaws.com/contents/1/1/1/b6221779e85b87c620decc8028aaf8188c000b26.epub: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. is thrown when i use s3 public urls

Example: var Book = ePub("https://venkitest1.s3.us-east-2.amazonaws.com/contents/1/1/1/b6221779e85b87c620decc8028aaf8188c000b26.epub");

This works - var Book = ePub("http://localhost:8000/storage/contents/1/1/1/32bfe62a1a8fab105588af74f468f333a4396b53.epub");

Any Help is appreciated.

Thank You.

  • Update: It now works with public s3 urls after i updated the bucket CORS configuration. But still no solution for Signed s3 urls. – Venkatesh Rao Dec 11 '17 at 08:20

2 Answers2

0

You need to add localhost:8000 to the CORS policy for your s3 bucket. http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

shiv255
  • 1
  • 2
  • Thanks for the reply. Yes i have added that which fixed issue **"No 'Access-Control-Allow-Origin' header is present"** while using s3 public url. But **"href is not defined"** exception is still thrown while using signed s3 urls. – Venkatesh Rao Dec 12 '17 at 04:51
0

Solution: Solved the issue by using handling the books as contained epubs by passing { contained: true }

Example: var Book = ePub("http://server.com/media.php?id=12345", { contained: true });