Last active
November 11, 2021 07:36
-
-
Save ptcampbell/7cd2e587e3f970f24720bc0a77750649 to your computer and use it in GitHub Desktop.
Worker script to call direct_upload endpoint and get URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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