{"record":{"id":"771bfce535a9dac7","repo":"jamiepine/voicebox","slug":"file-exceeds-import-audio-max-bytes-1024-10","errorCode":null,"errorMessage":"File exceeds {IMPORT_AUDIO_MAX_BYTES // (1024 * 1024)} MB limit.","messagePattern":"File exceeds (.+?) MB limit\\.","errorType":"http","errorClass":"HTTPException","httpStatus":413,"severity":"warning","filePath":"backend/routes/generations.py","lineNumber":442,"sourceCode":"    Designed for the story timeline so users can drop in music or other\n    non-TTS audio. The row points at a singleton \"Imported Audio\" profile\n    so the existing generation/story plumbing keeps working unchanged.\"\"\"\n    suffix = Path(file.filename or \"\").suffix.lower()\n    if suffix not in IMPORT_AUDIO_EXTENSIONS:\n        raise HTTPException(\n            status_code=400,\n            detail=f\"Unsupported audio format '{suffix}'. Allowed: {sorted(IMPORT_AUDIO_EXTENSIONS)}\",\n        )\n\n    chunks: list[bytes] = []\n    total = 0\n    while True:\n        chunk = await file.read(1024 * 1024)\n        if not chunk:\n            break\n        total += len(chunk)\n        if total > IMPORT_AUDIO_MAX_BYTES:\n            raise HTTPException(\n                status_code=413,\n                detail=f\"File exceeds {IMPORT_AUDIO_MAX_BYTES // (1024 * 1024)} MB limit.\",\n            )\n        chunks.append(chunk)\n    audio_bytes = b\"\".join(chunks)\n    if not audio_bytes:\n        raise HTTPException(status_code=400, detail=\"Empty audio file.\")\n\n    generation_id = str(uuid.uuid4())\n    target = config.get_generations_dir() / f\"{generation_id}{suffix}\"\n    target.write_bytes(audio_bytes)\n\n    try:\n        audio, sr = load_audio(str(target))\n        duration = float(len(audio) / sr) if sr else 0.0\n    except Exception as decode_err:\n        try:\n            target.unlink()","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/jamiepine/voicebox/blob/51f49dea198384b4eb6087b72c17057c6eb1c1cd/backend/routes/generations.py#L424-L460","documentation":"Returned by POST /generate/import when the cumulative uploaded byte total exceeds IMPORT_AUDIO_MAX_BYTES (200 * 1024 * 1024 = 200 MB). The endpoint streams the upload in 1 MB chunks and checks `total > IMPORT_AUDIO_MAX_BYTES` after each chunk, so the rejection happens mid-stream. HTTP 413 Payload Too Large.","triggerScenarios":"Uploading an audio file larger than 200 MB; uploading a file that is nominally under the limit but the streamed chunks push the running total past it on the last read.","commonSituations":"Long-form music mixes or uncompressed WAV masters exceeding 200 MB; a reverse proxy (nginx) with its own client_max_body_size set lower intercepting first; browser uploading a folder-compressed blob.","solutions":["Compress or trim the audio to under 200 MB before uploading (downsample, convert to mp3/flac).","If larger imports are genuinely needed, raise IMPORT_AUDIO_MAX_BYTES in backend/routes/generations.py AND raise the reverse proxy body limit (e.g. nginx client_max_body_size) to match.","Validate file size client-side before the upload starts to avoid a wasted partial transfer.","For very large media, split into segments."],"exampleFix":"// before\nupload(file);\n\n// after\nconst MAX = 200 * 1024 * 1024;\nif (file.size > MAX) { alert(`File exceeds ${MAX/1048576} MB`); return; }\nupload(file);","handlingStrategy":"validation","validationCode":"const MAX = 200 * 1024 * 1024;\nif (file.size > MAX) { alert(`File exceeds ${MAX/1048576} MB`); return; }\nawait upload(file);","typeGuard":"function withinImportLimit(file, limitBytes = 200 * 1024 * 1024) {\n  return file && typeof file.size === 'number' && file.size <= limitBytes;\n}","tryCatchPattern":"try {\n  const res = await fetch('/generate/import', { method:'POST', body: form });\n  if (res.status === 413) { alert('File too large'); return; }\n} catch (e) { console.error(e); }","preventionTips":["Check file.size before upload to avoid wasted bandwidth.","If raising the limit server-side, also raise the reverse proxy body limit.","Compress long-form audio before importing."],"tags":["fastapi","file-upload","audio","import","size-limit","payload-too-large"],"backgroundTag":null,"analyzedSha":"51f49dea198384b4eb6087b72c17057c6eb1c1cd","analyzedAt":"2026-08-12T16:51:42.824Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}