|
15 | 15 | if (files.length > 0) {
|
16 | 16 | files = [];
|
17 | 17 | }
|
18 |
| - // get only the first file |
19 |
| - // optionally: we need to handle multiple files, if we want to support document upload for example |
20 |
| - // for multimodal we only support one image at a time but we could support multiple PDFs |
21 | 18 | if (event.dataTransfer.items[0].kind === "file") {
|
22 |
| - const file = event.dataTransfer.items[0].getAsFile(); |
23 |
| - if (file) { |
24 |
| - // check if the file matches the mimeTypes |
25 |
| - if ( |
26 |
| - !mimeTypes.some((mimeType: string) => { |
27 |
| - const [type, subtype] = mimeType.split("/"); |
28 |
| - const [fileType, fileSubtype] = file.type.split("/"); |
29 |
| - return type === fileType && (subtype === "*" || fileSubtype === subtype); |
30 |
| - }) |
31 |
| - ) { |
32 |
| - setErrorMsg(`File type not supported. Only allowed: ${mimeTypes.join(", ")}`); |
33 |
| - files = []; |
34 |
| - return; |
35 |
| - } |
| 19 | + for (let i = 0; i < event.dataTransfer.items.length; i++) { |
| 20 | + const file = event.dataTransfer.items[i].getAsFile(); |
| 21 | +
|
| 22 | + if (file) { |
| 23 | + // check if the file matches the mimeTypes |
| 24 | + // else abort |
| 25 | + if ( |
| 26 | + !mimeTypes.some((mimeType: string) => { |
| 27 | + const [type, subtype] = mimeType.split("/"); |
| 28 | + const [fileType, fileSubtype] = file.type.split("/"); |
| 29 | + return type === fileType && (subtype === "*" || fileSubtype === subtype); |
| 30 | + }) |
| 31 | + ) { |
| 32 | + setErrorMsg(`Some file type not supported. Only allowed: ${mimeTypes.join(", ")}`); |
| 33 | + files = []; |
| 34 | + return; |
| 35 | + } |
| 36 | +
|
| 37 | + // if file is bigger than 10MB abort |
| 38 | + if (file.size > 10 * 1024 * 1024) { |
| 39 | + setErrorMsg("Some file is too big. (10MB max)"); |
| 40 | + files = []; |
| 41 | + return; |
| 42 | + } |
36 | 43 |
|
37 |
| - // if file is bigger than 10MB abort |
38 |
| - if (file.size > 10 * 1024 * 1024) { |
39 |
| - setErrorMsg("Image is too big. (2MB max)"); |
40 |
| - files = []; |
41 |
| - return; |
| 44 | + // add the file to the files array |
| 45 | + files = [...files, file]; |
42 | 46 | }
|
43 |
| - files = [file]; |
44 |
| - onDrag = false; |
45 | 47 | }
|
| 48 | + onDrag = false; |
46 | 49 | }
|
47 | 50 | }
|
48 | 51 | }
|
|
0 commit comments