Skip to content

Commit 97722e1

Browse files
committed
fix: restore Firefox drag-and-drop support and fix webkitRelativePath handling
- Add fallback to event.dataTransfer.files when webkitGetAsEntry() returns null (fixes Firefox drag-and-drop regression) - Set webkitRelativePath on files obtained via FileSystemFileEntry for consistency - Strip leading slash from entry.fullPath in both addFromDir and handleDroppedItems - Add folder selection button with webkitdirectory input for cross-browser folder uploads
1 parent e4ee75f commit 97722e1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/sections/shared/file-uploader/file-upload-input/FileUploadInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ const FileUploadInput = ({ fileRepository, datasetPersistentId }: FileUploadInpu
143143
}
144144

145145
const droppedItems = event.dataTransfer.items
146+
const droppedFiles = event.dataTransfer.files
146147

147148
if (droppedItems.length > 0) {
148149
if (operationType === OperationType.REPLACE_FILE && droppedItems.length > 1) {
149150
toast.error(t('fileUploader.replaceFileMultipleError'))
150151
return
151152
}
152153

153-
handleDroppedItems(droppedItems)
154+
handleDroppedItems(droppedItems, droppedFiles)
154155
}
155156
}
156157

src/sections/shared/file-uploader/useFileUploadOperations.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export function useFileUploadOperations(config: FileUploadOperationsConfig): Fil
174174
})
175175

176176
Object.defineProperty(fileWithPath, 'webkitRelativePath', {
177-
value: entry.fullPath,
177+
value: entry.fullPath.startsWith('/') ? entry.fullPath.slice(1) : entry.fullPath,
178178
writable: true
179179
})
180180

@@ -202,7 +202,16 @@ export function useFileUploadOperations(config: FileUploadOperationsConfig): Fil
202202
handledViaEntry = true
203203
const fse = entry as FileSystemFileEntry
204204
fse.file((file) => {
205-
void uploadOneFile(file)
205+
// Create a new File with webkitRelativePath set for consistency
206+
const fileWithPath = new File([file], file.name, {
207+
type: file.type,
208+
lastModified: file.lastModified
209+
})
210+
Object.defineProperty(fileWithPath, 'webkitRelativePath', {
211+
value: entry.fullPath.startsWith('/') ? entry.fullPath.slice(1) : entry.fullPath,
212+
writable: true
213+
})
214+
void uploadOneFile(fileWithPath)
206215
})
207216
}
208217
})

0 commit comments

Comments
 (0)