Skip to content

Commit f8f5e0c

Browse files
tiberiuichimrstoenescu
authored andcommitted
Feature: build upload urls with a thenable url factory (quasarframework#604)
* Feature: build upload urls with a thenable url factory * Update QUploader.vue
1 parent 23c2810 commit f8f5e0c

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/components/uploader/QUploader.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ export default {
137137
type: String,
138138
required: true
139139
},
140+
urlFactory: {
141+
type: Function,
142+
required: false
143+
},
140144
additionalFields: {
141145
type: Array,
142146
default: () => []
@@ -308,15 +312,21 @@ export default {
308312
reject(xhr)
309313
}
310314
311-
xhr.open(this.method, this.url, true)
312-
if (this.headers) {
313-
Object.keys(this.headers).forEach(key => {
314-
xhr.setRequestHeader(key, this.headers[key])
315-
})
316-
}
315+
const resolver = this.urlFactory
316+
? this.urlFactory(file)
317+
: Promise.resolve(this.url)
317318
318-
this.xhrs.push(xhr)
319-
xhr.send(form)
319+
resolver.then(url => {
320+
xhr.open(this.method, url, true)
321+
if (this.headers) {
322+
Object.keys(this.headers).forEach(key => {
323+
xhr.setRequestHeader(key, this.headers[key])
324+
})
325+
}
326+
327+
this.xhrs.push(xhr)
328+
xhr.send(form)
329+
})
320330
})
321331
},
322332
upload () {

0 commit comments

Comments
 (0)