Chunk upload fix for `multipart/form-data` form request.

We forced the `header` for the chunk upload request to be `multipart/form-data` but the header must be set auotmatically when sending the `FormData`. This was causing the backend being unable to read parameters sent

Changed the way we stop the chunk process when the upload fails in `upload` phase. We no longer set the `file.active = false` since that would prevent the next file to start uploading
master
José Cámara 8 years ago
parent 78ca7c569f
commit 8417e11b3a

@ -37,9 +37,7 @@ import ChunkUploadDefaultHandler from './chunk/ChunkUploadHandler'
import InputFile from './InputFile.vue' import InputFile from './InputFile.vue'
const CHUNK_DEFAULT_OPTIONS = { const CHUNK_DEFAULT_OPTIONS = {
headers: { headers: {},
'Content-Type': 'application/json'
},
action: '', action: '',
minSize: 1048576, minSize: 1048576,
maxActive: 3, maxActive: 3,

@ -168,6 +168,13 @@ export default class ChunkUploadHandler {
*/ */
pause () { pause () {
this.file.active = false this.file.active = false
this.stopChunks()
}
/**
* Stops all the current chunks
*/
stopChunks () {
this.chunksUploading.forEach(chunk => { this.chunksUploading.forEach(chunk => {
chunk.xhr.abort() chunk.xhr.abort()
chunk.active = false chunk.active = false
@ -208,7 +215,7 @@ export default class ChunkUploadHandler {
start () { start () {
request({ request({
method: 'POST', method: 'POST',
headers: Object.assign(this.headers, { headers: Object.assign({}, this.headers, {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}), }),
url: this.action, url: this.action,
@ -275,9 +282,7 @@ export default class ChunkUploadHandler {
this.updateFileProgress() this.updateFileProgress()
chunk.xhr = createRequest({ chunk.xhr = createRequest({
method: 'POST', method: 'POST',
headers: Object.assign(this.headers, { headers: this.headers,
'Content-Type': 'multipart/form-data'
}),
url: this.action url: this.action
}) })
@ -298,7 +303,7 @@ export default class ChunkUploadHandler {
chunk.uploaded = true chunk.uploaded = true
} else { } else {
if (chunk.retries-- <= 0) { if (chunk.retries-- <= 0) {
this.pause() this.stopChunks()
return this.reject('upload') return this.reject('upload')
} }
} }
@ -307,7 +312,7 @@ export default class ChunkUploadHandler {
}).catch(() => { }).catch(() => {
chunk.active = false chunk.active = false
if (chunk.retries-- <= 0) { if (chunk.retries-- <= 0) {
this.pause() this.stopChunks()
return this.reject('upload') return this.reject('upload')
} }
@ -324,7 +329,7 @@ export default class ChunkUploadHandler {
request({ request({
method: 'POST', method: 'POST',
headers: Object.assign(this.headers, { headers: Object.assign({}, this.headers, {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}), }),
url: this.action, url: this.action,

Loading…
Cancel
Save