Skip to content

Commit 29bef03

Browse files
Merge pull request #296 from brunokunace/feature/multiupload
Multiupload can send one file per request
2 parents 264a4b6 + 734517c commit 29bef03

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

docs/components/upload.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ API:
6565
parameters:
6666
description: It determines whether to show the upload button or not.
6767
default: true
68+
- name: single-upload
69+
type: Boolean
70+
parameters:
71+
description: This causes each file to be sent separately on each request. Only used when multiple prop is true
72+
default: false
6873
---
6974

7075
# Upload

src/components/vsUpload/vsUpload.vue

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
type="button"
3232
title="Upload"
3333
class="btn-upload-all"
34-
@click="uploadx('all')">
34+
@click="upload('all')">
3535
<i
3636
translate="no"
3737
class="material-icons notranslate">
@@ -70,7 +70,7 @@
7070
height: `${img.percent}%`
7171
}"
7272
class="btn-upload-file"
73-
@click="uploadx(index)">
73+
@click="upload(index)">
7474
<i
7575
translate="no"
7676
class="material-icons notranslate">
@@ -146,6 +146,10 @@
146146
showUploadButton: {
147147
default: true,
148148
type: Boolean
149+
},
150+
singleUpload: {
151+
default: false,
152+
type: Boolean
149153
}
150154
},
151155
data:()=>({
@@ -286,9 +290,7 @@
286290
this.uploadx('all')
287291
}
288292
},
289-
uploadx(index){
290-
let self = this
291-
const xhr = new XMLHttpRequest();
293+
upload(index) {
292294
const formData = new FormData();
293295
let postFiles = Array.prototype.slice.call(this.filesx);
294296
if(typeof index == 'number'){
@@ -298,18 +300,32 @@
298300
return !item.hasOwnProperty('remove')
299301
})
300302
}
301-
302-
303-
postFiles.forEach((filex)=>{
304-
formData.append(this.fileName, filex, filex.name)
305-
})
306-
307303
const data = this.data || {};
308-
309304
for (var key in data) {
310305
formData.append(key, data[key]);
311306
}
312307
308+
if(this.singleUpload) {
309+
postFiles.forEach((filex)=>{
310+
const formData = new FormData();
311+
for (var key in data) {
312+
formData.append(key, data[key]);
313+
}
314+
formData.append(this.fileName, filex, filex.name)
315+
316+
this.uploadx(index, formData)
317+
})
318+
} else {
319+
postFiles.forEach((filex)=>{
320+
formData.append(this.fileName, filex, filex.name)
321+
})
322+
this.uploadx(index, formData)
323+
}
324+
},
325+
uploadx(index, formData){
326+
let self = this
327+
const xhr = new XMLHttpRequest();
328+
313329
xhr.onerror = function error(e) {
314330
self.$emit('on-error',e)
315331
if(typeof index == 'number'){

0 commit comments

Comments
 (0)