|
208 | 208 | this.$emit('upload'); |
209 | 209 |
|
210 | 210 | if (!this.readonly) { |
211 | | - files = this.allowMultiple ? files : [files[0]]; |
212 | | - files = await this.validateFiles(files); |
| 211 | + try { |
| 212 | + files = this.allowMultiple ? files : [files[0]]; |
| 213 | + files = await this.validateFiles(files); |
213 | 214 |
|
214 | | - // Show errors if relevant |
215 | | - if (this.totalUploadSize > this.availableSpace) { |
216 | | - this.showStorageExceededAlert = true; |
217 | | - return; |
218 | | - } else if (this.unsupportedFiles.length) { |
219 | | - this.showUnsupportedFilesAlert = true; |
220 | | - } else if (this.tooLargeFiles.length) { |
221 | | - this.showTooLargeFilesAlert = true; |
222 | | - } |
223 | | - return this.handleUploads(files).then(fileUploads => { |
224 | | - const objects = fileUploads.map(f => f.fileObject).filter(f => !f.error); |
225 | | - if (fileUploads.length) { |
226 | | - for (const fileUpload of fileUploads) { |
227 | | - fileUpload.uploadPromise |
228 | | - .then(fileObject => { |
229 | | - if (isFunction(this.uploadCompleteHandler)) { |
230 | | - this.uploadCompleteHandler(this.getFileUpload(fileObject.id)); |
231 | | - } |
232 | | - }) |
233 | | - .catch(() => {}); |
234 | | - } |
235 | | - if (isFunction(this.uploadingHandler)) { |
236 | | - this.uploadingHandler(this.allowMultiple ? objects : objects[0]); |
237 | | - } |
| 215 | + // Show errors if relevant |
| 216 | + if (this.totalUploadSize > this.availableSpace) { |
| 217 | + this.showStorageExceededAlert = true; |
| 218 | + return; |
| 219 | + } else if (this.unsupportedFiles.length) { |
| 220 | + this.showUnsupportedFilesAlert = true; |
| 221 | + } else if (this.tooLargeFiles.length) { |
| 222 | + this.showTooLargeFilesAlert = true; |
238 | 223 | } |
239 | | - return objects; |
240 | | - }); |
| 224 | + return this.handleUploads(files).then(fileUploads => { |
| 225 | + const objects = fileUploads.map(f => f.fileObject).filter(f => !f.error); |
| 226 | + if (fileUploads.length) { |
| 227 | + for (const fileUpload of fileUploads) { |
| 228 | + fileUpload.uploadPromise |
| 229 | + .then(fileObject => { |
| 230 | + if (isFunction(this.uploadCompleteHandler)) { |
| 231 | + this.uploadCompleteHandler(this.getFileUpload(fileObject.id)); |
| 232 | + } |
| 233 | + }) |
| 234 | + .catch(() => {}); |
| 235 | + } |
| 236 | + if (isFunction(this.uploadingHandler)) { |
| 237 | + this.uploadingHandler(this.allowMultiple ? objects : objects[0]); |
| 238 | + } |
| 239 | + } |
| 240 | + return objects; |
| 241 | + }); |
| 242 | + } finally { |
| 243 | + this.resetFileInput(); |
| 244 | + } |
241 | 245 | } |
242 | 246 | }, |
243 | 247 | handleUploads(files) { |
|
255 | 259 | return fileUploads.filter(Boolean); |
256 | 260 | }); |
257 | 261 | }, |
| 262 | + resetFileInput() { |
| 263 | + this.$refs.fileUpload.value = ''; |
| 264 | + }, |
258 | 265 | }, |
259 | 266 | $trs: { |
260 | 267 | unsupportedFilesHeader: 'Unsupported files', |
|
0 commit comments