---
title: "Accept checked uploads"
description: "Accept photos and files checked on the server: size and sniffed type, EXIF and GPS stripped, quotas counted in files and bytes, and the file stored with its row in one mutation, or claimed after an upload URL."
canonical_url: "https://nuxt-backend.dev/docs/build/data/files/checked-uploads"
---
# Accept checked uploads

> Accept photos and files checked on the server: size and sniffed type, EXIF and GPS stripped, quotas counted in files and bytes, and the file stored with its row in one mutation, or claimed after an upload URL.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

A Panels author uploads a reference photo for a strip, and your app keeps it only when it is an image you accept, under your limits, with its location data removed. Convex file storage holds the bytes and hands out upload URLs. The package adds the checks: the size, the type read from the bytes, EXIF and GPS stripping, file and byte quotas, an owner record, and one mutation that stores the file and your row together.

## Set up storage

Create `backend/storage.ts` once, with the limits every upload must meet:

```ts [backend/storage.ts]
import { setupStorage } from 'nuxt-backend/storage'
import { billing } from './billing'
import { components } from './_generated/api'

export const storage = setupStorage(components, {
  maxSize: 8 * 1024 * 1024,
  accept: ['image/png', 'image/jpeg', 'image/webp'],
  stripMetadata: true,
  quota: { files: 'photos', bytes: 'storageBytes' },
  billing,
})

// The functions useUpload, <UploadField> and <StorageImage> call.
export const { generateUploadUrl, getFileUrl } = storage.api
```

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        maxSize
      </code>
    </td>
    
    <td>
      <code>
        10 * 1024 * 1024
      </code>
      
      , 10 MB
    </td>
    
    <td>
      The largest file kept, in bytes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        accept
      </code>
    </td>
    
    <td>
      <code>
        ['image/png', 'image/jpeg', 'image/webp']
      </code>
    </td>
    
    <td>
      The types kept, as read from the file's first bytes. Leave out SVG and HTML: both can carry script
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stripMetadata
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Removes EXIF, XMP, IPTC and GPS data from JPEG, PNG and WebP images before they are kept. A photo taken sideways keeps its orientation alone, so it still shows upright
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quota.files
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      A number, or a quota key of your <a href="https://nuxt-backend.dev/docs/build/billing/subscriptions/quotas">
        billing catalog
      </a>
      
      : how many files the billing entity may keep
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quota.bytes
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      The same for the total bytes kept. Each file counts its size after stripping. A catalog key shows the files and bytes kept in <code>
        useFeatures().quotas
      </code>
      
       and <code>
        billing.getQuota
      </code>
      
      , beside anything your own mutations claim under the same key
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        billing
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      Your <code>
        billing
      </code>
      
       instance, which a quota key needs: it reads the limit from the billing entity's plan, and the files are counted against that entity
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        rateLimiter
      </code>
    </td>
    
    <td>
      the package's own
    </td>
    
    <td>
      Your <code>
        rateLimiter
      </code>
      
      , whose <code>
        upload
      </code>
      
       limit bounds upload URLs (<a href="https://nuxt-backend.dev/docs/ship/security/rate-limits">
        rate limits
      </a>
      
      )
    </td>
  </tr>
</tbody>
</table>

`generateUploadUrl` answers signed-in accounts only, at a per-account rate beside the package's other [rate limits](https://nuxt-backend.dev/docs/ship/security/rate-limits). `getFileUrl` returns a file's URL to its owner and to members of its workspace, and `null` to anyone else.

## Store a photo in one mutation

For a photo, send the bytes to your own mutation. `storage.store` checks them, strips the metadata, stores the file and records its owner, in the same transaction as your row. A refused file leaves nothing behind: no row, no bytes, nothing to sweep. `storage.store` is for files people upload; an image a model generates goes through `ctx.storeImage` in the job step instead ([Label AI-generated content](https://nuxt-backend.dev/docs/build/ai/provenance#label-a-result)).

```ts [backend/strips.ts]
import { backendError } from 'nuxt-backend/functions'
import { v } from 'convex/values'
import { workspace } from './functions'
import { storage } from './storage'

export const addPhoto = workspace.mutation({
  args: { id: v.id('strips'), photo: v.bytes() },
  handler: async (ctx, { id, photo }) => {
    const strip = await ctx.db.get('strips', id)
    if (strip?.workspaceId !== ctx.workspace.id) throw backendError('forbidden', { reason: 'other_workspace' })
    const { storageId } = await storage.store(ctx, photo, { userId: ctx.user.id, workspaceId: ctx.workspace.id })
    await storage.release(ctx, strip.photoId) // the photo it replaces, if any
    await ctx.db.patch('strips', id, { photoId: storageId })
  },
})
```

```vue [app/components/PhotoPicker.vue]
<script setup lang="ts">
import { api } from '#backend/api'

import type { Id } from '#backend/dataModel'

const props = defineProps<{ stripId: Id<'strips'> }>()
const addPhoto = useMutation(api.strips.addPhoto)
const busy = ref(false)
const refusal = ref<string | null>(null)

async function onPick(event: Event) {
  const file = (event.target as HTMLInputElement).files?.[0]
  if (!file) return
  busy.value = true
  refusal.value = null
  try {
    await addPhoto({ id: props.stripId, photo: await file.arrayBuffer() })
  }
  catch (failure) {
    refusal.value = getBackendError(failure)?.message ?? 'Could not keep that photo. Try another one.'
  }
  finally {
    busy.value = false
  }
}
</script>

<template>
  <label>
    Reference photo
    <input type="file" accept="image/png,image/jpeg,image/webp" :aria-disabled="busy || undefined" @change="onPick">
  </label>
  <p v-if="busy" role="status">Checking the photo…</p>
  <p v-if="refusal" role="alert">{{ refusal }}</p>
</template>
```

`store(ctx, bytes, owner)` returns `{ storageId, size, contentType }`. It works in a mutation because Convex 1.48 lets `ctx.storage` store a file there. A Convex function argument holds up to 16 MiB (checked on 2026-10-25), so this path suits photos and documents. Send anything larger through an upload URL.

Each file has one owner record:

<table>
<thead>
  <tr>
    <th>
      Owner
    </th>
    
    <th>
      Who may read the file
    </th>
    
    <th>
      What deletes it
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        { userId }
      </code>
    </td>
    
    <td>
      The account that uploaded it
    </td>
    
    <td>
      <code>
        release
      </code>
      
      , or the account's erasure
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        { userId, workspaceId }
      </code>
    </td>
    
    <td>
      Every member of that workspace
    </td>
    
    <td>
      <code>
        release
      </code>
      
      , or the workspace's deletion. It stays when the uploader leaves
    </td>
  </tr>
</tbody>
</table>

Store the id as `v.string()`: the file lives in the `backend` component's storage, so it is not an id of your schema.

## Upload a large file with an upload URL

The browser can also send the bytes straight to Convex storage, with progress and cancel. The base module's `useUpload` asks for an upload URL, sends the file and resolves with a storage id. Your mutation then claims it:

```ts [backend/strips.ts]
export const attachFile = workspace.mutation({
  args: { id: v.id('strips'), fileId: v.string() },
  handler: async (ctx, { id, fileId }) => {
    const strip = await ctx.db.get('strips', id)
    if (strip?.workspaceId !== ctx.workspace.id) throw backendError('forbidden', { reason: 'other_workspace' })
    await storage.claim(ctx, fileId, { userId: ctx.user.id, workspaceId: ctx.workspace.id })
    await ctx.db.patch('strips', id, { attachmentId: fileId })
  },
})
```

```vue [app/components/AttachmentPicker.vue]
<script setup lang="ts">
import { api } from '#backend/api'

import type { Id } from '#backend/dataModel'

const props = defineProps<{ stripId: Id<'strips'> }>()
const attachFile = useMutation(api.strips.attachFile)
const { upload, isUploading, progress, error, cancel } = useUpload(api.storage.generateUploadUrl)
const refusal = ref<string | null>(null)

async function onPick(event: Event) {
  const file = (event.target as HTMLInputElement).files?.[0]
  const fileId = file ? await upload(file) : null
  if (!fileId) return
  refusal.value = null
  try {
    await attachFile({ id: props.stripId, fileId })
  }
  catch (failure) {
    refusal.value = getBackendError(failure)?.message ?? 'Could not keep that file. Try another one.'
  }
}
</script>

<template>
  <input type="file" :aria-disabled="isUploading || undefined" @change="onPick">
  <progress v-if="isUploading" :value="progress" />
  <button v-if="isUploading" type="button" @click="cancel">Cancel upload</button>
  <p v-if="error || refusal" role="alert">{{ error?.message ?? refusal }}</p>
</template>
```

`claim(ctx, storageId, owner)` checks the stored size and the quotas at once, and refuses a file that is gone or already claimed. A mutation cannot read a file's bytes, so the type check and the metadata stripping run next, in the component, before the file's URL is served. Until then `getFileUrl` reads `null`. A file whose bytes are not a type you accept is deleted, and its URL stays `null`.

An upload nobody will claim, one the person dropped or one your own check refused, can go at once with `storage.discard(ctx, fileId)`, from a mutation or an action. It deletes only an unclaimed upload: a kept file, anyone's, stays as it is, and so does an id with no file. It answers whether bytes went, `false` on a second call, so calling it twice is safe. The sweep deletes an unclaimed upload after a day anyway ([Keep storage clean](https://nuxt-backend.dev/docs/build/data/files/cleanup#what-the-sweep-deletes)).

An upload URL takes a file of any size for an hour, and the upload must finish within two minutes (checked on 2026-10-25). The size check happens once the file has arrived, so the per-account rate on upload URLs is what bounds abuse. For many files at once, the base module's `useUploadQueue(api.storage.generateUploadUrl)` uploads with bounded concurrency; claim each id as it lands.

## Check, moderate and keep an upload in one call

A photo people upload usually passes three steps before it is kept: your own check that it may go where it is headed, a [content check](https://nuxt-backend.dev/docs/build/ai/content-safety#check-uploads) of what it shows, and the mutation that claims it. The content check reads the file's bytes, so the three run in an action. `storage.acceptUpload` runs them in that order, and settles what becomes of the upload when one refuses:

```ts [backend/strips.ts]
import { backendError } from 'nuxt-backend/functions'
import { v } from 'convex/values'
import { internal } from './_generated/api'
import { internalMutation, internalQuery } from './_generated/server'
import { ai } from './ai'
import { workspace } from './functions'
import { storage } from './storage'

import type { Doc } from './_generated/dataModel'

// The strip, when it belongs to the caller's workspace.
function ownStrip(strip: Doc<'strips'> | null, workspaceId: string): Doc<'strips'> {
  if (strip?.workspaceId !== workspaceId) throw backendError('forbidden', { reason: 'other_workspace' })
  return strip
}

// Before the classifier reads anything: the strip is the caller's, and the
// photo a new upload, not a file kept already.
export const checkPhoto = internalQuery({
  args: { id: v.id('strips'), photoId: v.string(), workspaceId: v.string() },
  handler: async (ctx, { id, photoId, workspaceId }) => {
    ownStrip(await ctx.db.get('strips', id), workspaceId)
    if (await storage.fileUrl(ctx, photoId)) throw backendError('invalid_input', { field: 'file', reason: 'upload_claimed' })
  },
})

// The strip is read again: it may have changed since the check. The photo
// it replaces is released, so its bytes leave the quota.
export const keepPhoto = internalMutation({
  args: { id: v.id('strips'), photoId: v.string(), userId: v.string(), workspaceId: v.string() },
  handler: async (ctx, { id, photoId, userId, workspaceId }) => {
    const strip = ownStrip(await ctx.db.get('strips', id), workspaceId)
    await storage.claim(ctx, photoId, { userId, workspaceId })
    if (strip.photoId) await storage.release(ctx, strip.photoId)
    await ctx.db.patch('strips', id, { photoId })
  },
})

export const attachPhoto = workspace.action({
  args: { id: v.id('strips'), photoId: v.string() },
  handler: (ctx, { id, photoId }) => storage.acceptUpload(ctx, photoId, {
    check: () => ctx.runQuery(internal.strips.checkPhoto, { id, photoId, workspaceId: ctx.workspace.id }),
    safety: ai,
    about: { subject: id },
    keep: () => ctx.runMutation(internal.strips.keepPhoto, { id, photoId, userId: ctx.user.id, workspaceId: ctx.workspace.id }),
  }),
})
```

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        check
      </code>
    </td>
    
    <td>
      Your check, run first. It refuses by throwing, or by returning <code>
        false
      </code>
      
      , which refuses the upload as <a href="https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input">
        <code>
          invalid_input
        </code>
      </a>
      
       on <code>
        file
      </code>
      
      , and passes by returning nothing, <code>
        null
      </code>
      
       or <code>
        true
      </code>
      
      . A query that returns a row passes once wrapped: <code>
        check: async () => { await ctx.runQuery(…) }
      </code>
      
      . A refusal here costs no classifier call. Without a check, the classifier reads whatever id the caller sends before <code>
        keep
      </code>
      
       can refuse it
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        safety
      </code>
    </td>
    
    <td>
      Your <code>
        ai
      </code>
      
       from <code>
        setupAi
      </code>
      
      : <code>
        ai.requireSafe
      </code>
      
       reads the upload as an image and refuses one the <a href="https://nuxt-backend.dev/docs/build/ai/content-safety#set-a-moderation-policy">
        moderation policy
      </a>
      
       blocks. A file that is no image is refused <code>
        unsupported_type
      </code>
      
       and discarded, so pass <code>
        false
      </code>
      
       for other files. <code>
        false
      </code>
      
       keeps the upload with no content check
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        about
      </code>
    </td>
    
    <td>
      What the classifier's record of a flagged upload names: <code>
        { subject, stage }
      </code>
      
      , and <code>
        userId
      </code>
      
       or <code>
        owner
      </code>
      
       when the upload is not the signed-in person's. The stage is <code>
        'upload'
      </code>
      
       unless you give one
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        keep
      </code>
    </td>
    
    <td>
      Your internal mutation that claims the upload with <code>
        storage.claim
      </code>
      
       and writes your row. What it returns, <code>
        acceptUpload
      </code>
      
       returns
    </td>
  </tr>
</tbody>
</table>

When a step refuses the upload itself, with [`invalid_input`](https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input) on `file` or `images` (the classifier's `content_blocked`, the claim's `too_large` or `unsupported_type`, a check that returns `false`) or [`quota_exceeded`](https://nuxt-backend.dev/docs/reference/backend/errors#quota_exceeded), the same file would be refused again: `acceptUpload` discards it at once and throws the refusal. A kept file is never discarded: your check's `upload_claimed` names a file kept already, a strip's photo or a panel, and that file stays as it is. Any other error, such as a strip of another workspace, a rate limit, a classifier that is down or an `invalid_input` on a field of your own that `keep` refused, a caption, says nothing about the file: the upload stays, unclaimed until the daily sweep, and the page can send the same id again. Pass the action to `<UploadField>`'s `:claim` as it is. The field shows [`rate_limited`](https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited), [`unavailable`](https://nuxt-backend.dev/docs/reference/backend/errors#unavailable) and [`unauthenticated`](https://nuxt-backend.dev/docs/reference/backend/errors#unauthenticated) as `error`, with a Try again button that sends the same id. Every other refusal, the `forbidden` of another workspace's strip among them, leaves it `refused`, asking for another file.

The steps are separate transactions: a row your check read can change before `keep` runs, so `keep` checks again whatever must still hold, such as the strip's workspace or room for one more photo. `keep` also releases the photo it replaces: a replaced photo that stays claimed still counts against the quota, and the sweep never deletes it. [Hooks and guarantees](https://nuxt-backend.dev/docs/reference/backend/hooks) states what the package promises about `check` and `keep`.

## Place the ready-made field

`<UploadField>` is the upload URL flow as a labelled field: a file picker reached by keyboard or click, drag and drop as a second path, progress, cancel and a live region. Give it a `claim` function. It calls it once the upload lands, ties a refusal to the field, and sets `v-model` only when the claim went through:

```vue [app/components/AttachmentField.vue]
<script setup lang="ts">
import { api } from '#backend/api'

import type { Id } from '#backend/dataModel'

const props = defineProps<{ stripId: Id<'strips'> }>()
const attachFile = useMutation(api.strips.attachFile)
const fileId = ref<string | null>(null)
</script>

<template>
  <UploadField
    v-model="fileId"
    accept="image/png,image/jpeg,image/webp"
    :claim="id => attachFile({ id: props.stripId, fileId: id })"
  />
</template>
```

A refusal, a catalog error your `claim` throws (`invalid_input`, `quota_exceeded`, …), leaves the field `refused`: its alert says why, and the picker asks for another file. A failure on the way (the network, a service that is down, a rate limit) leaves it `error`, with a Try again button that picks up where the file stopped: the claim alone once the file is stored, the transfer otherwise. To change the file in the browser before it uploads, a photo shrunk or re-encoded, pass `:prepare="(file, signal) => blob"`: it runs once per file, a retry sends what it returned, and a refusal it throws reads like the claim's. The field runs on the base module's `useUploadQueue`, one file at a time.

Its words come from the `upload` label group, and it keeps the [component contract](https://nuxt-backend.dev/docs/reference/components#the-component-contract): `data-upload` hooks, a `data-state` for each step, and a live region for progress and refusals. [Upload and contact forms](https://nuxt-backend.dev/docs/reference/components/forms) lists its props, slots and parts.

## Prepare photos in the browser

A phone's photo is often several megabytes, sideways until its EXIF orientation is read, tagged with where it was taken, and on an iPhone a HEIC, which `stripMetadata` can't strip and so refuses. `preparePhoto` makes a photo ready on the device, before it is sent: it decodes it, HEIC included, turns it upright, scales it down to a long edge and re-encodes it on a canvas, which keeps the pixels and drops every metadata tag, GPS included. Pass it as the field's `prepare`:

```vue [app/components/StripPhotoField.vue]
<script setup lang="ts">
import { api } from '#backend/api'

import type { Id } from '#backend/dataModel'

const props = defineProps<{ stripId: Id<'strips'> }>()
const attach = useAction(api.strips.attachPhoto)
const photoId = ref<string | null>(null)
</script>

<template>
  <UploadField
    v-model="photoId"
    accept="image/*,.heic,.heif"
    :prepare="preparePhoto"
    :claim="id => attach({ id: props.stripId, photoId: id })"
  />
</template>
```

The field's `accept` can offer HEIC now: the server receives a JPEG. With options, call it yourself: `:prepare="(file, signal) => preparePhoto(file, { longEdge: 1536, signal })"`. The base module's `useUploadQueue` takes it the same way, `prepare: (file, _item, signal) => preparePhoto(file, signal)`.

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        longEdge
      </code>
    </td>
    
    <td>
      <code>
        2048
      </code>
    </td>
    
    <td>
      The longest side sent, in pixels. A larger photo is scaled down to it; a smaller one keeps its size
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        type
      </code>
    </td>
    
    <td>
      <code>
        'image/jpeg'
      </code>
    </td>
    
    <td>
      <code>
        'image/jpeg'
      </code>
      
      , <code>
        'image/webp'
      </code>
      
       or <code>
        'image/png'
      </code>
      
      . A transparent area of a JPEG turns white. Safari has no WebP encoder: its canvas writes a PNG instead, several times larger, so there the photo is sent as a JPEG
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quality
      </code>
    </td>
    
    <td>
      <code>
        0.85
      </code>
    </td>
    
    <td>
      The encoder's quality for JPEG and WebP, from 0 to 1
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        signal
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      Stops the work when aborted. The second argument may be the signal alone, as the field passes it
    </td>
  </tr>
</tbody>
</table>

A browser opens most photos itself, and Safari opens HEIC. Elsewhere a HEIC needs a decoder: install `heic-to`, an optional peer, and `preparePhoto` loads it the first time a HEIC arrives, never before. It loads the package's `heic-to/csp` build, about 3 MB of JavaScript (LGPL-3.0) that compiles nothing at runtime, so the [security headers](https://nuxt-backend.dev/docs/ship/security#content-security-policy) need no `'unsafe-eval'`. It decodes in a worker started from a `blob:` URL, and with `heic-to` installed the module adds `blob:` to `worker-src` for it. A HEIC the decoder hasn't opened within a minute of its loading is refused as `unreadable`, and until the decoder answers again, later HEICs are refused at once rather than queued behind it. Where the decoder fails, or `heic-to` is not installed, `preparePhoto` tries the browser's own `<img>`, which opens HEIC in Safari, before it refuses the photo as `unreadable`.

```bash
npm install heic-to
```

A photo over 100 megapixels is refused before it is decoded, as is a small file whose header claims that many: opened, it would take 400 MB or more, which a phone's tab can't be counted on for. The width and height are read from the JPEG, PNG or WebP header; for another type the browser decides.

A file that is no photo, one too large to open, or one the browser can't open is refused with a `PhotoPrepError`: [`invalid_input`](https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input) on `file`, reason `unsupported_type`, `too_large` or `unreadable`. It is a `ConvexError` with the catalog's data, so the field reads it as `refused`, `getBackendError` reads it like the deployment's refusals, and its message says why. `isPhotoFile(file)` says whether a dropped or pasted file is worth preparing, an image type or a HEIC the device sent untyped, for a drop zone of your own. SVG and GIF are refused as `unsupported_type`: an SVG has no size of its own to draw at, and a GIF's animation would be cut to its first frame. Send a GIF as it is, without `preparePhoto`, when your `accept` takes one. The deployment still checks and strips whatever arrives: preparing a photo is for privacy and size, never a security boundary.

## What the checks do

<table>
<thead>
  <tr>
    <th>
      Check
    </th>
    
    <th>
      One-mutation store
    </th>
    
    <th>
      Upload URL and claim
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Size against <code>
        maxSize
      </code>
    </td>
    
    <td>
      Before anything is stored
    </td>
    
    <td>
      At claim, on the stored size
    </td>
  </tr>
  
  <tr>
    <td>
      Type against <code>
        accept
      </code>
    </td>
    
    <td>
      Read from the bytes, before storing
    </td>
    
    <td>
      Read from the bytes after the claim; a mismatch deletes the file
    </td>
  </tr>
  
  <tr>
    <td>
      EXIF, XMP and GPS removed
    </td>
    
    <td>
      Before storing
    </td>
    
    <td>
      After the claim, before the URL is served
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quota.files
      </code>
      
       and <code>
        quota.bytes
      </code>
    </td>
    
    <td>
      Before storing
    </td>
    
    <td>
      At claim
    </td>
  </tr>
  
  <tr>
    <td>
      Owner record
    </td>
    
    <td>
      In your transaction
    </td>
    
    <td>
      In your transaction
    </td>
  </tr>
</tbody>
</table>

The type comes from the file's signature (its magic bytes), never from the name or the type the browser declared. Convex keeps only the declared type, so this check is what the package adds. A wildcard in `accept` (`image/*`) never admits SVG or HTML: name `image/svg+xml` to keep SVG files. Every kept upload is stored again under its sniffed type, so no URL serves a file with the type its uploader declared. Stripping rewrites the image's container without re-encoding the pixels, so quality is unchanged; the size counted against `quota.bytes` is the size after stripping. A JPEG ends at its first image: an appended preview or gain map, with EXIF of its own, goes too. HEIC, HEIF, AVIF and TIFF keep EXIF the stripper can't remove, so while `stripMetadata` is on a wildcard never admits them, and naming one in `accept` throws; pass `stripMetadata: false` to keep them as they are.

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Situation
    </th>
    
    <th>
      Refusal
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The file is too large, of a type you did not accept, gone, or already claimed
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input">
        <code>
          invalid_input
        </code>
      </a>
      
       on the <code>
        file
      </code>
      
       field, reason <code>
        too_large
      </code>
      
      , <code>
        unsupported_type
      </code>
      
      , <code>
        upload_gone
      </code>
      
       or <code>
        upload_claimed
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        preparePhoto
      </code>
      
       can't make the picked file ready, in the browser
    </td>
    
    <td>
      <code>
        invalid_input
      </code>
      
       on <code>
        file
      </code>
      
      , reason <code>
        unsupported_type
      </code>
      
       (no photo: not an image, or an SVG or a GIF), <code>
        too_large
      </code>
      
       (over 100 megapixels) or <code>
        unreadable
      </code>
      
       (a photo this browser can't open), as a <code>
        PhotoPrepError
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      A quota has no room left
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#quota_exceeded">
        <code>
          quota_exceeded
        </code>
      </a>
      
      , with the plans that allow more
    </td>
  </tr>
  
  <tr>
    <td>
      A signed-out caller asks for an upload URL
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#unauthenticated">
        <code>
          unauthenticated
        </code>
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Upload URLs are asked for too fast
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited">
        <code>
          rate_limited
        </code>
      </a>
      
      , with <code>
        retryAfter
      </code>
    </td>
  </tr>
</tbody>
</table>

A refusal rolls back your whole mutation, so your row never points at a file that was not kept. [Handle errors](https://nuxt-backend.dev/docs/build/data/read-write/errors) shows how a page reads each one.

## Limits

- **Native gaps.** Convex stores the declared type without reading the bytes, sets no size limit on an upload URL, and serves any file URL to whoever holds it. The package covers the first two; [expiring private URLs](https://nuxt-backend.dev/docs/build/data/files/images#serve-a-private-file-for-a-while) cover the third.
- **What stripping covers.** JPEG, PNG and WebP. Other types are kept as they arrived, so leave them out of `accept` when location data matters.
- **Not a content check.** What an image shows is content safety: [Keep content safe](https://nuxt-backend.dev/docs/build/ai/content-safety).
- **release checks no owner.** Pass it an id read from your own row, never one from a client's arguments. `discard` may take a client's id: it never deletes a kept file.
- **Cost.** Stored bytes and bandwidth count against your Convex plan: [Convex](https://nuxt-backend.dev/docs/services/convex#costs-and-limits).

## Test it

```ts [backend/strips.test.ts]
import { asUser, defineBackendTestApp } from 'nuxt-backend/test'
import { expect, test } from 'vitest'
import { api } from './_generated/api'
import schema from './schema'

const testApp = defineBackendTestApp(schema, import.meta.glob('./**/*.ts'))

test('refuses a file that is not an image', async () => {
  const author = await asUser(testApp())
  const id = await author.mutation(api.strips.create, { title: 'Monday' })
  const text = new TextEncoder().encode('not an image').buffer
  await expect(author.mutation(api.strips.addPhoto, { id, photo: text }))
    .rejects.toMatchObject({ data: { code: 'invalid_input', field: 'file' } })
})
```

[Test backend functions](https://nuxt-backend.dev/docs/develop/testing/functions) covers `defineBackendTestApp` and `asUser`.

## Related

- [Show images](https://nuxt-backend.dev/docs/build/data/files/images): `<StorageImage>`, the image provider and expiring URLs.
- [Keep storage clean](https://nuxt-backend.dev/docs/build/data/files/cleanup): `release`, the sweep, export and erasure.
- [Convex](https://nuxt-backend.dev/docs/services/convex): file storage, its plan limits and region.
- [Upload and contact forms](https://nuxt-backend.dev/docs/reference/components/forms): `<UploadField>` in full.
- [Part 3 of the tutorial](https://nuxt-backend.dev/docs/start/tutorial/uploads): photos in Panels, end to end.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
