{"record":{"id":"c3ba7ae301dbe81d","repo":"remotion-dev/remotion","slug":"file-with-name-assetpath-already-exists-and-is","errorCode":null,"errorMessage":"File with name ${assetPath} already exists and is different","messagePattern":"File with name (.+?) already exists and is different","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-studio/src/download-remote-asset.ts","lineNumber":142,"sourceCode":"\t\tthrow error;\n\t} finally {\n\t\tclearTimeout(timeout);\n\t}\n\n\tconst fileType = detectFileType(contents);\n\tif (!isImageFileType(fileType)) {\n\t\tthrow new Error('Remote asset is not a supported image');\n\t}\n\n\tconst assetPath = getRemoteAssetFilename({fileType, url});\n\tconst existing = Object.entries(getProject().publicFiles ?? {}).find(\n\t\t([path]) => path.replace(/^\\/+/, '') === assetPath,\n\t)?.[1];\n\tif (\n\t\texisting !== undefined &&\n\t\tgetPublicFileSize(existing) !== contents.byteLength\n\t) {\n\t\tthrow new Error(\n\t\t\t`File with name ${assetPath} already exists and is different`,\n\t\t);\n\t}\n\n\tif (existing === undefined) {\n\t\tawait writeStaticFile({\n\t\t\tcontents: contents.slice().buffer,\n\t\t\tfilePath: assetPath,\n\t\t});\n\t}\n\n\treturn {\n\t\tassetPath,\n\t\tcreated: existing === undefined,\n\t\telement: getRemoteAssetElement({assetPath, fileType}),\n\t\tsizeInBytes: contents.byteLength,\n\t};\n};","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/remotion-dev/remotion/blob/10db9de07356446fb0edb3c3ae211369b693d18b/packages/browser-studio/src/download-remote-asset.ts#L124-L160","documentation":"The imported asset's path is derived deterministically from the URL basename and the sniffed file type by getRemoteAssetFilename(). If a public file already exists at that path but its size differs from the freshly downloaded bytes, Browser Studio refuses to overwrite it. Re-importing the byte-identical file is idempotent (created: false); importing a different file that maps to the same name is an error.","triggerScenarios":"Calling downloadRemoteAssetInBrowserStudio when getProject().publicFiles already contains an entry whose path equals the computed assetPath (URL basename, sanitized, with the detected type's extension appended if missing) and whose byte length differs from the new download. Typical when two different images share a filename across URLs, or the remote file changed after a previous import.","commonSituations":"Importing hero.png from two different sites into the same project; the origin updated the image in place after the first import; two variants (light/dark) with the same basename.","solutions":["Delete or rename the existing public file with the same name, then import again","Rename the remote asset (or its URL filename) so it no longer collides","If the remote file legitimately changed, remove the stale copy from public/ first to accept the new bytes","Re-import the exact same URL - identical files are deduplicated without error"],"exampleFix":"// before: importing a different image whose basename collides with public/poster.png\nawait downloadRemoteAssetInBrowserStudio({getProject, request: {url: 'https://other-site.example.com/poster.png'}, writeStaticFile});\n\n// after: import the variant under a distinct filename\nawait downloadRemoteAssetInBrowserStudio({getProject, request: {url: 'https://other-site.example.com/poster-dark.png'}, writeStaticFile});","handlingStrategy":"validation","validationCode":"const expectedName = decodeURIComponent(new URL(url).pathname.split('/').pop() ?? 'image');\nconst existing = Object.entries(project.publicFiles ?? {}).find(\n  ([path]) => path.replace(/^\\/+/, '') === expectedName,\n)?.[1];\nif (existing !== undefined) {\n  // confirm with the user whether to delete/rename the existing public file before importing\n  throw new Error(`A public file named ${expectedName} already exists - resolve the conflict first`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await downloadRemoteAssetInBrowserStudio({getProject, request, writeStaticFile});\n} catch (e) {\n  if (/already exists and is different/.test(String((e as Error).message))) {\n    // offer to delete the existing public file or import under a different URL/filename\n  } else throw e;\n}","preventionTips":["Check project.publicFiles for the URL's basename before showing an import button","Give remote variants distinct filenames (poster-dark.png, not poster.png)","Treat re-import of an unchanged URL as safe - only different bytes collide"],"tags":["browser-studio","public-folder","conflict","remote-asset"],"backgroundTag":"filename-collision","analyzedSha":"10db9de07356446fb0edb3c3ae211369b693d18b","analyzedAt":"2026-08-22T21:45:17.748Z","contentChangedAt":"2026-08-22T21:45:17.748Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}