How to GET a binary file and POST it somewhere else?

I’d like to use a worker to upload images to the new CF Images service.
The basic upload procedure includes saving the file locally and submit it as a Form POST.

curl -X POST "https://api.cloudflare.com/client/v4/accounts/023e105f4ecef8ad9ca31a8372d0c353/images/v1" \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     --form '[email protected]/Users/kyle/Desktop/logo.png' 

I believe workers don’t have access to local storage, so I’m puzzled on how to save and submit the binary file contents between the GET and the POST.
Save it temporarily in a KV variable?
Encode it and keep it in memory?
Thanks for any suggestion

You can upload the file to Workers, I have a blog post on this - Handling File Uploads with Cloudflare Workers

Then you can just upload to Images from there

3 Likes

Yes, to add, the direct docs:

https://developers.cloudflare.com/workers/platform/compatibility-dates#formdata-parsing-supports-file

1 Like