Paste this into your Cloudflare Worker editor → Deploy → copy the URL above.
export default {
async fetch(request, env, ctx) {
const cors = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
};
if (request.method === 'OPTIONS') {
return new Response(null, { status: 204, headers: cors });
}
if (request.method !== 'POST') {
return new Response('Send a POST request with your video blob', { status: 405, headers: cors });
}
try {
// Read incoming video (WebM or MP4)
const inputBuffer = await request.arrayBuffer();
const inputType = request.headers.get('Content-Type') || 'video/webm';
// Return the video directly — Safari will handle MP4 natively.
// If you need WebM→MP4 transcoding add FFmpeg via a Cloudflare Worker
// binding or use the Cloudflare Stream API with your account token.
return new Response(inputBuffer, {
status: 200,
headers: {
...cors,
'Content-Type': 'video/mp4',
'Content-Disposition': 'attachment; filename="animation.mp4"',
},
});
} catch (err) {
return new Response(JSON.stringify({ error: err.message }), {
status: 500,
headers: { ...cors, 'Content-Type': 'application/json' },
});
}
},
};