Skip to content

r2 file upload

… put a file into r2 through a Worker:

const filename = crypto.randomUUID()
const uploadedObject = await env.bucketName.put(filename, request.body, {
  httpMetadata: request.headers,
})
return new Response(filename, { headers: { etag: uploadedObject?.httpEtag } })

then upload with curl like so:

curl -X PUT -H "content-type: video/mp4" -d @abc.mp4 https://r2.example.com/