{"record":{"id":"01df505ee37907f5","repo":"dotnet/aspnetcore","slug":"there-is-no-file-with-id-fileid-the-file-list","errorCode":null,"errorMessage":"There is no file with ID ${fileId}. The file list may have changed. See https://aka.ms/aspnet/blazor-input-file-multiple-selections.","messagePattern":"There is no file with ID (.+?)\\. The file list may have changed\\. See https://aka\\.ms/aspnet/blazor-input-file-multiple-selections\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/InputFile.ts","lineNumber":117,"sourceCode":"    contentType: format,\n    blob: resizedImageBlob ? resizedImageBlob : originalFile.blob,\n  };\n\n  elem._blazorFilesById[result.id] = result;\n\n  return result;\n}\n\nasync function readFileData(elem: InputElement, fileId: number): Promise<Blob> {\n  const file = getFileById(elem, fileId);\n  return file.blob;\n}\n\nexport function getFileById(elem: InputElement, fileId: number): BrowserFile {\n  const file = elem._blazorFilesById[fileId];\n\n  if (!file) {\n    throw new Error(`There is no file with ID ${fileId}. The file list may have changed. See https://aka.ms/aspnet/blazor-input-file-multiple-selections.`);\n  }\n\n  return file;\n}\n","sourceCodeStart":99,"sourceCodeEnd":122,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Web.JS/src/InputFile.ts#L99-L122","documentation":"`getFileById` looks up a browser file the user selected via Blazor's `InputFile` component by indexing `elem._blazorFilesById[fileId]`. Each selected file is assigned an incremental ID by the framework; the map only lives for the lifetime of the current input's file list. If the requested ID is absent the lookup throws, pointing at the multiple-selections guidance because re-picking or clearing files renumbers the list.","triggerScenarios":"Calling `readFileData`/`getFileById` (through `IBrowserFile` open-read APIs or `InputFile` JS interop) with a `fileId` that was never assigned, was assigned on a different input element, or became invalid after the file list changed (re-select, clear, or multiple-selection changes).","commonSituations":"Caching an `IBrowserFile` reference across postbacks in Blazor Server after the input's file list was replaced; passing an id from a disposed/cleared `<InputFile>`; using the same input for multiple selection rounds and referencing a stale id from an earlier round; desync between server-tracked ids and client `_blazorFilesById` after a reconnect.","solutions":["Re-read files in the same `OnInputFileChange` handler where the `IBrowserFile` was obtained — do not retain the id past the current selection.","If you must process asynchronously, copy the stream to memory/storage first, then release the id before the user can change the selection.","Clear the input (`InputFile.Reset()`) deliberately rather than letting the user re-pick, so the id lifecycle is explicit.","On Blazor Server, guard long-running file work against circuit reconnects which can invalidate the client-side file map."],"exampleFix":"// before\nvar file = e.GetMultipleFiles(int.MaxValue)[0];\n// ...user picks new files, then later:\nawait using var fs = file.OpenReadStream(); // stale id -> throw\n\n// after\nvar file = e.GetMultipleFiles(int.MaxValue)[0];\nawait using var ms = new MemoryStream();\nawait using (var fs = file.OpenReadStream(maxAllowedSize: long.MaxValue))\n    await fs.CopyToAsync(ms); // consume immediately, same selection","handlingStrategy":"validation","validationCode":"function hasFile(elem: HTMLInputElement, fileId: number): boolean {\n  return !!(elem as any)._blazorFilesById && fileId in (elem as any)._blazorFilesById;\n}","typeGuard":null,"tryCatchPattern":"try { return await readFileData(elem, fileId); }\ncatch (e) { if (/no file with ID/.test(e.message)) { /* re-prompt user or abort */ return null; } throw e; }","preventionTips":["Consume IBrowserFile streams in the same OnInputFileChange that produced them.","Copy file bytes to durable storage before allowing the selection to change.","Reset the InputFile deliberately rather than letting re-selection renumber ids.","Do not cache file ids across circuit reconnects on Blazor Server."],"tags":["input-file","interop","blazor","file-upload","lifecycle"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}