Skip to content

Instantly share code, notes, and snippets.

@ptcampbell
Last active November 11, 2021 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptcampbell/7cd2e587e3f970f24720bc0a77750649 to your computer and use it in GitHub Desktop.
Save ptcampbell/7cd2e587e3f970f24720bc0a77750649 to your computer and use it in GitHub Desktop.
Worker script to call direct_upload endpoint and get URL
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
const url = "https://api.cloudflare.com/client/v4/accounts/:account_id/images/v1/direct_upload"
async function handleRequest(request) {
const config = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer :token',
},
}
const response = await fetch(url, config)
const newResponse = new Response(response.body, response)
newResponse.headers.append("Access-Control-Allow-Origin", "*")
newResponse.headers.append("Access-Control-Allow-Headers", "*")
return newResponse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment