I have a function who send chunks of file with an async request (tmp is my chunk)
uploadChunk: function (uploadId, content, offset) {
var tmp = content.slice(offset, offset + constants.ChunkSize);
restRequest({
method: 'POST',
url: 'file/chunk?uploadId=' + uploadId + '&offset=' + offset,
data: tmp,
processData: false,
contentType: false
}).then(function (resp) {
// When the upload is finished, we have an json object with a field '_modelType'
if (typeof resp._modelType === "undefined" || resp._modelType == null) {
return this.uploadChunk(uploadId, content, resp.received);
}
// Here, file is fully upload
}.bind(this));
}
I would like to return a promise only when my file is fully upload and use like that:
this.uploadChunk(uploadId, content, 0).then(function (){
console.log("My file is uploaded");
.... // use my new file
})
I tried to create a promise but once my function is called recursively, the resolve function is no longer defined..
Need help :)