windmill-labs/windmill · error · Error
Uploading a file in a different root folder than the previou
Error message
Uploading a file in a different root folder than the previous files
What it means
uploadFileToS3() enforces that all files in a folder-only upload share one root folder, tracked in uploadedFolderRoot. A file whose root differs from previously uploaded files throws 'Uploading a file in a different root folder than the previous files'.
Source
Thrown at frontend/src/lib/components/common/fileUpload/FileUpload.svelte:195
let uploadedFolderRoot: string | undefined = undefined
async function uploadFileToS3(fileToUpload: File & { path?: string }, fileToUploadKey: string) {
if (fileToUpload === undefined || fileToUploadKey === undefined) {
return
}
let path: string | undefined = undefined
let fileExtension: string | undefined = undefined
if (folderOnly) {
const relativePath = fileToUpload.webkitRelativePath || fileToUpload.path
if (!relativePath) {
throw new Error('Missing file relative path')
}
const rootFolder = relativePath.split('/')[0]
if (!rootFolder) {
throw new Error('Missing root folder')
}
if (uploadedFolderRoot && rootFolder !== uploadedFolderRoot) {
throw new Error('Uploading a file in a different root folder than the previous files')
} else {
uploadedFolderRoot = rootFolder
}
path = uniqueFolderPrefix + relativePath
} else if (randomFileKey) {
fileExtension = fileToUpload.name.split('.').pop()
if (emptyString(fileExtension)) {
fileExtension = undefined
}
} else {
path =
typeof pathTransformer == 'function'
? ((await pathTransformer?.({
file: fileToUpload
})) ?? fileToUploadKey)
: fileToUploadKey
}
const uploadData: FileUploadData = {View on GitHub (pinned to e474e8803c)
Solutions
- Clear/reset the upload component (and its uploadedFolderRoot state) before starting a new folder batch
- Upload one folder per batch, or use separate FileUpload instances per root
- If mixing is intended, disable folderOnly mode or move files under a common root
Example fix
// before // uploading 'dirA/a.txt' then 'dirB/b.txt' into same component // after uploadedFolderRoot = undefined // reset before new batch, or keep one root per batch
Defensive patterns
Strategy: try-catch
Validate before calling
if (uploadedFolderRoot) {
const root = (file.webkitRelativePath || file.path).split('/')[0]
if (root !== uploadedFolderRoot) {
console.error('Reset the upload or use a component per root folder')
}
} Type guard
function sameRoot(f: File, currentRoot: string | undefined): boolean {
const root = (f.webkitRelativePath || (f as any).path || '').split('/')[0]
return !currentRoot || root === currentRoot
} Try / catch
try {
await uploadFileToS3(file)
} catch (e) {
if (e.message.startsWith('Uploading a file in a different root folder')) {
uploadedFolderRoot = undefined // reset state, restart the batch
} else throw e
} Prevention
- One folder per upload batch; reset state between picks
- Use separate FileUpload components per folder
- Validate all selected files share a root before starting the batch
When it happens
Trigger: Uploading/mixing files from two different selected folders in the same FileUpload instance (e.g. selecting another folder after a first batch, or adding stray files with a different top-level directory).
Common situations: Selecting a second folder into the same component mid-batch; merging directory uploads in a loop; component state (uploadedFolderRoot) persisting between picks.
Related errors
- Missing file relative path
- Missing root folder
- Not implemented in Windmill's Open Source repository
- Failed to load S3 file: ${response.status} ${response.status
- deleteS3File: s3 key is required
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/8b95ba2218edae49.
Report an issue: GitHub.