> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Transcribe audio and video users upload to Supabase Storage

> A tested Supabase recipe for Lovable, Bolt and other Supabase apps: a user uploads a recording to a private Storage bucket, an Edge Function signs the file for an hour and sends it to Importly, and the timestamped transcript lands in a Postgres table.

Plenty of apps built on Supabase let users upload their own recordings: meetings, voice notes, lectures, interviews. The file is in a private Storage bucket, and the app needs the words. An Edge Function can't transcribe the file itself, and reading a big file into one can end it with a [546](/docs/integrations/supabase-edge-function-limits.md). You don't have to move the file at all: sign it for an hour and send Importly the signed link. Importly fetches the file, transcribes it and calls your webhook.

This recipe builds on [Save transcripts to Supabase from an Edge Function](/docs/integrations/supabase-edge-functions.md). Set that up first: it has the `transcripts` table, the shared `importly.ts` helper, the `importly-webhook` function that saves each finished transcript, and the sweep for missed webhooks. Here you add:

* a private `uploads` bucket where each user can only write to and read their own folder;
* `transcribe-upload`, which checks the file belongs to the caller, signs it and starts the transcript.

## 1. The bucket

Run this in the SQL editor or add it as a migration. Each user uploads to a folder named after their user ID, so the policies can check the first part of the path.

```sql theme={null}
-- private, 50 MB per file (the most the Free plan allows)
insert into storage.buckets (id, name, public, file_size_limit)
values ('uploads', 'uploads', false, 52428800);

create policy "Users upload to their own folder"
  on storage.objects for insert to authenticated
  with check (bucket_id = 'uploads' and (storage.foldername(name))[1] = (select auth.uid())::text);

create policy "Users read their own uploads"
  on storage.objects for select to authenticated
  using (bucket_id = 'uploads' and (storage.foldername(name))[1] = (select auth.uid())::text);
```

## 2. Upload from the app

The upload goes straight from the browser to Storage with the user's session. Nothing passes through your functions.

```ts theme={null}
const { data: { user } } = await supabase.auth.getUser()
const path = `${user.id}/${crypto.randomUUID()}-${file.name}`

const { error } = await supabase.storage.from('uploads').upload(path, file, { contentType: file.type })
```

A path in someone else's folder fails with `new row violates row-level security policy`.

## 3. Sign it and start the transcript

The frontend calls this function with the user's session and the path it just uploaded. The function makes sure the path is in the caller's own folder before it signs anything, so one user can't get another user's file transcribed.

```ts supabase/functions/transcribe-upload/index.ts theme={null}
import { createClient } from 'npm:@supabase/supabase-js@2'
import { importly } from '../_shared/importly.ts'

const supabase = createClient(Deno.env.get('SUPABASE_URL')!, Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!)

const cors = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
}

Deno.serve(async (req) => {
  if (req.method === 'OPTIONS') return new Response('ok', { headers: cors })

  const token = req.headers.get('Authorization')?.replace('Bearer ', '') ?? ''
  const { data: { user } } = await supabase.auth.getUser(token)
  if (!user) return Response.json({ error: 'Sign in first' }, { status: 401, headers: cors })

  // Only files in the caller's own folder
  const { path } = await req.json()
  if (typeof path !== 'string' || !path.startsWith(`${user.id}/`) || path.includes('..')) {
    return Response.json({ error: 'Not your file' }, { status: 403, headers: cors })
  }

  // An hour is plenty: Importly fetches the file when the job starts
  const { data: signed, error: signError } = await supabase.storage.from('uploads').createSignedUrl(path, 60 * 60)
  if (signError) return Response.json({ error: 'File not found' }, { status: 404, headers: cors })

  const { status, body } = await importly('/transcribe', {
    method: 'POST',
    body: JSON.stringify({
      url: signed.signedUrl,
      // an upload has no captions, so go straight to speech-to-text
      mode: 'ai',
      // stop a long recording before it costs more than $0.50
      maxCostDollars: 0.5,
      webhookUrl: `${Deno.env.get('SUPABASE_URL')}/functions/v1/importly-webhook`,
    }),
  })
  if (!body.success) return Response.json({ error: body.error, code: body.code }, { status, headers: cors })

  // Store the path, not the signed link: the link stops working in an hour
  const { data, error } = await supabase
    .from('transcripts')
    .insert({ user_id: user.id, url: `uploads/${path}`, job_id: body.data.jobId, status: body.data.status })
    .select('id, status')
    .single()
  if (error) return Response.json({ error: error.message }, { status: 500, headers: cors })

  return Response.json(data, { headers: cors })
})
```

```bash theme={null}
supabase functions deploy transcribe-upload
```

The `importly-webhook` function from the transcripts recipe saves the result to the row when it's ready, and the sweep catches a missed webhook. Neither needs a change.

## 4. Call it and show the transcript

```ts theme={null}
const { data: row, error } = await supabase.functions.invoke('transcribe-upload', { body: { path } })

// later, or from a Realtime subscription on the transcripts table
const { data } = await supabase.from('transcripts').select('status, text, segments').eq('id', row.id).single()
```

`segments` has the start and end of each line in seconds, so you can show the transcript next to the recording and seek the player when a user clicks a line. To let users search across everything they've uploaded, add [Supabase transcript search](/docs/integrations/supabase-transcript-search.md).

## What we tested

We uploaded a 2 minute 41 second MP3 (a public-domain LibriVox reading of the Gettysburg Address) to a private bucket as a signed-in user, signed it with this function's checks and sent the signed link to `POST /transcribe` with `"mode": "ai"`. With `"wait": 60` the finished transcript, 18 timestamped segments, came back in the response 13 seconds later and cost \$0.03. A second user asking for the first user's path got `403`, a path that didn't exist got `404`, and an upload into another user's folder was refused by the policy.

## Things to know

The signed link only has to work until Importly fetches the file, which is when the job starts. If you queue many uploads at once, an hour still covers it. Don't store the link: store the path and sign it again when you need it.

Supabase's Free plan caps a single file at 50 MB, about 50 minutes of 128 kbps MP3 or a few minutes of phone video. Paid plans can raise the bucket limit. Importly only needs the link, so a bigger file doesn't change the function.

For a video upload you only want the words from, the same function works: Importly transcribes the audio track.

> [!NOTE]
>
> Speech-to-text is \$0.01 per minute, and `maxCostDollars` stops a long recording before it's charged. Try it free, no card required. See [Pricing & credits](/docs/billing.md).

## Let your agent write it

Using Lovable's chat, Bolt, Claude Code or Cursor on this project? Connect the [MCP server](/docs/integrations/mcp.md) and ask it to transcribe uploaded files with Importly: it reads the same integration guide and can test with a real file first. See [Build with your agent](/docs/integrations/build-with-your-agent.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.