I am trying to serve our image files from our AWS S3 bucket using CF worker. I have found this guide:
https://support.cloudflare.com/hc/en-us/articles/360013791312-Fetching-object-storage-assets-through-the-Cloudflare-CDN-using-a-Cloudflare-Worker
but after following step by step I get this error in the worker editor:
NoSuchKey
The specified key does not exist./index.html0C1A594F49644B29Mr2oq8h8Nlquve5YQTqULFVYXGKp6QhPaLTNhE2C6QZ6r+omzBk1OysVbX0V0U8S9ozXpuoNOmM=
1 Like
Iβm using the below basic script and changing the return fetch url as mentioned in the guide.
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(βhttps://Cloudflare-example-space.nyc3.digitaloceanspaces.comβ + path)
}
addEventListener(βfetchβ, event => {
event.respondWith(handleRequest(event.request))
})
Xaq
4
Did you replace https://Cloudflare-example-space.nyc3.digitaloceanspaces.com
and path with your own URL/path?
he specified key does not exist
is AWS 404 error. Check your URL to AWS.
I have one worker that is that exact code, different url.
Are the objects public?
I replaced https://Cloudflare-example-space.nyc3.digitaloceanspaces.com with our own url, do I also have to add anything for (+path)?
I believe our objects are public because I can view the image files from any browser using the image url.
But i may have to recheck the bucket status.
Here is my retried script but iβm getting ReferenceError: S3 not define
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(βhttps://newbium.s3.amazonaws.comβ + s3.amazonaws.com/newbium)
}
addEventListener(βfetchβ, event => {
event.respondWith(handleRequest(event.request))
})
Xaq
9
TheURL you are trying to fetch is:
https://newbium.s3.amazonaws.com/s3.amazonaws.com/newbium
and is incorrect. When I try to open it in browser:
Whatever resource you want to use first check the URL in browser.
Ok found the correct amazon url but getting the access denied error so need to update our bucket permission to make our objects public.
Thanks a lot for your help.
1 Like