CF Worker For Accessing Amazon S3 Images

We have a bucket setup on Amazon S3 for images. I’m following the guide at and am stuck.

We’ve setup the Cname and that’s working just fine. The issue is with the worker configuration.

Step 2 of the doc above references a recipe. But there’s no script to copy on that page ( I found a worker from another thread here and tried that but am getting the error:

Uncaught SyntaxError: Invalid or unexpected token at line 5

Here’s the code I am trying:

async function handleRequest(request) {
const parsedUrl = new URL(request.url)
let path = parsedUrl.pathname

let lastSegment = path.substring(path.lastIndexOf(’/’))
if (lastSegment.indexOf(’.’) === -1) {
path += ‘/index.html’

return fetch(“” + path)

addEventListener(‘fetch’, event => {

It’s hard given it’s not set as code, but those apostrophes are the wrong kind of apostrophe. Substitute them with the correct one.

Basically you have the top one, set it as the lower one in here:

Yep, that was it. Thanks.

1 Like