Supabase Edge Functions: download YouTube, TikTok and Instagram videos
Supabase Edge Functions run on Deno, so the CrawlFetch call is plain fetch. Save the result to Supabase Storage.
How it fits together
The function resolves the URL, downloads the file and uploads it to a Storage bucket, returning the stored path.
Supabase Edge Functions example
import { createClient } from "jsr:@supabase/supabase-js@2";Deno.serve(async (req) => {const { url } = await req.json();const r = await fetch("https://api.crawlfetch.com/v1/resolve?" + new URLSearchParams({ url }), {headers: { Authorization: "Bearer " + Deno.env.get("CRAWLFETCH_KEY") },});if (!r.ok) return new Response("resolve failed", { status: r.status });const video = await r.json();const file = await fetch(video.downloadUrl);const supabase = createClient(Deno.env.get("SUPABASE_URL")!, Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!);const path = "videos/" + video.id + ".mp4";await supabase.storage.from("media").upload(path, await file.blob(), { contentType: "video/mp4" });return Response.json({ path, title: video.title });});
Notes for Supabase Edge Functions
- Set the key with
supabase secrets set CRAWLFETCH_KEY=…. - For long videos, prefer a resumable (TUS) upload over a single blob.
FAQ
Can I trigger it from a database insert?
Yes — call the function from a database webhook when a row with a video URL is inserted.
Related
Last updated 2026-10-25