Commit 97d68a6a authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: multiple files input


Co-Authored-By: default avatarEntaigner <61445450+entaigner@users.noreply.github.com>
parent cd79afb4
...@@ -328,10 +328,10 @@ ...@@ -328,10 +328,10 @@
]; ];
}; };
const inputFiles = e.dataTransfer?.files; const inputFiles = Array.from(e.dataTransfer?.files);
if (inputFiles && inputFiles.length > 0) { if (inputFiles && inputFiles.length > 0) {
const file = inputFiles[0]; inputFiles.forEach((file) => {
console.log(file, file.name.split('.').at(-1)); console.log(file, file.name.split('.').at(-1));
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) { if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
reader.readAsDataURL(file); reader.readAsDataURL(file);
...@@ -349,6 +349,7 @@ ...@@ -349,6 +349,7 @@
); );
uploadDoc(file); uploadDoc(file);
} }
});
} else { } else {
toast.error($i18n.t(`File not found.`)); toast.error($i18n.t(`File not found.`));
} }
...@@ -467,6 +468,7 @@ ...@@ -467,6 +468,7 @@
bind:files={inputFiles} bind:files={inputFiles}
type="file" type="file"
hidden hidden
multiple
on:change={async () => { on:change={async () => {
let reader = new FileReader(); let reader = new FileReader();
reader.onload = (event) => { reader.onload = (event) => {
...@@ -482,7 +484,8 @@ ...@@ -482,7 +484,8 @@
}; };
if (inputFiles && inputFiles.length > 0) { if (inputFiles && inputFiles.length > 0) {
const file = inputFiles[0]; const _inputFiles = Array.from(inputFiles);
_inputFiles.forEach((file) => {
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) { if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
reader.readAsDataURL(file); reader.readAsDataURL(file);
} else if ( } else if (
...@@ -501,6 +504,7 @@ ...@@ -501,6 +504,7 @@
uploadDoc(file); uploadDoc(file);
filesInputElement.value = ''; filesInputElement.value = '';
} }
});
} else { } else {
toast.error($i18n.t(`File not found.`)); toast.error($i18n.t(`File not found.`));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment