Skip to content

Commit 3c3cc75

Browse files
authored
🐛 fix(DragUpload): resolve issue with pasting clipboard images in Safari (#7961)
1 parent 5b22320 commit 3c3cc75

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/components/DragUpload/useDragUpload.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,22 @@ const getFileListFromDataTransferItems = async (items: DataTransferItem[]) => {
3737
const filePromises: Promise<File[]>[] = [];
3838
for (const item of items) {
3939
if (item.kind === 'file') {
40-
const entry = item.webkitGetAsEntry();
41-
if (entry) {
42-
filePromises.push(processEntry(entry));
40+
// Safari browser may throw error when using FileSystemFileEntry.file()
41+
// So we prioritize using getAsFile() method first for better browser compatibility
42+
const file = item.getAsFile();
43+
44+
if (file) {
45+
filePromises.push(
46+
new Promise((resolve) => {
47+
resolve([file]);
48+
}),
49+
);
4350
} else {
44-
const file = item.getAsFile();
45-
46-
if (file)
47-
filePromises.push(
48-
new Promise((resolve) => {
49-
resolve([file]);
50-
}),
51-
);
51+
const entry = item.webkitGetAsEntry();
52+
53+
if (entry) {
54+
filePromises.push(processEntry(entry));
55+
}
5256
}
5357
}
5458
}

0 commit comments

Comments
 (0)