From 29c09d9ea251b764427890d2f3eeabee15c5cc5a Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala <60499540+chiragchhatrala@users.noreply.github.com> Date: Wed, 22 Feb 2023 21:30:07 +0530 Subject: [PATCH] File upload fixes (#93) Co-authored-by: Julien Nahum --- app/Service/Storage/StorageFileNameParser.php | 1 + resources/js/components/forms/FileInput.vue | 101 ++++++++++-------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/app/Service/Storage/StorageFileNameParser.php b/app/Service/Storage/StorageFileNameParser.php index 6907533..0b1eddb 100644 --- a/app/Service/Storage/StorageFileNameParser.php +++ b/app/Service/Storage/StorageFileNameParser.php @@ -30,6 +30,7 @@ class StorageFileNameParser { if ($this->fileName && $this->extension) { $fileName = substr($this->fileName, 0, 50).'_'.$this->uuid.'.'.$this->extension; + $fileName = preg_replace('#\p{C}+#u', '', $fileName); // avoid CorruptedPathDetected exceptions return mb_convert_encoding($fileName, 'UTF-8', 'UTF-8'); } return $this->uuid; diff --git a/resources/js/components/forms/FileInput.vue b/resources/js/components/forms/FileInput.vue index d4dc996..c1c33b2 100644 --- a/resources/js/components/forms/FileInput.vue +++ b/resources/js/components/forms/FileInput.vue @@ -8,12 +8,16 @@ @@ -58,7 +68,7 @@

- Upload {{ multiple?'file(s)':'a file' }} + Upload {{ multiple ? 'file(s)' : 'a file' }}

@@ -86,8 +96,8 @@ />
- Upload {{ multiple?'file(s)':'a file' }} + Upload {{ multiple ? 'file(s)' : 'a file' }} or drag and drop

@@ -119,14 +129,17 @@ {{ file.file.name }}

- + - + +
@@ -150,7 +163,7 @@ export default { props: { multiple: { type: Boolean, default: true }, mbLimit: { type: Number, default: 5 }, - accept: { type: String, default: "" } + accept: { type: String, default: '' } }, data: () => ({ @@ -166,13 +179,13 @@ export default { currentUrl () { return this.form[this.name] }, - acceptExtensions(){ - if(this.accept){ - return this.accept.split(",").map((i) => { - return "."+i.trim() - }).join(",") + acceptExtensions () { + if (this.accept) { + return this.accept.split(',').map((i) => { + return '.' + i.trim() + }).join(',') } - return "" + return '' } }, @@ -209,9 +222,9 @@ export default { if (!droppedFiles) return - droppedFiles.forEach(file => { - this.uploadFileToServer(file) - }) + for (let i = 0; i < droppedFiles.length; i++) { + this.uploadFileToServer(droppedFiles.item(i)) + } }, openFileUpload () { this.$refs['actual-input'].click()