How to upload a zipfile to R2?
I'm trying to upload a zipfile to R2.
My worker receives the zip file as formdata:
const formData = await req.formData();
then I get the file inside formData:
const file = formData.get('file');
and put
it in R2
await env.MODELS_BUCKET.put(file);
also, I've tried
await env.MODELS_BUCKET.put(file.stream());
but it gives the following error:
Can anyone help me with this? What am I doing wrong?2 Replies
You’re not providing a filename
put is filename and then body - two args
Oh I got it. Im putting the file in the first parameter, where it supposed to be the filename.
Btw, I found a great example online. Want to share it here as a reference because I did exactly the same
https://reffect.co.jp/en/cloudflare/cloudflare-r2-basic/#workers-configuration
Tagged as solved already, @kiannh. Thanks