I'm using angular-file-upload
module by danialfarid (https://github.com/danialfarid/angular-file-upload) and it works great.
I've been able to integrate in my wrapper service for REST calls and I can actually upload several images with $q.all()
and keeping track of their progress.
However, I can't correctly identify the single images I'm uploading, because the file identifier gets continuosly changed by the for loop.
uploadPhotos: function (files) {
var deferred = $q.defer()
var queue = []
for (var i = 0; i < files.length; i++) {
var file = files[i];
var up = $upload.upload({
url: locationURI +'/photos',
file: file,
fileFormDataName: 'image'
}).then(
function (data) {
console.log(data)
},
function (err) {
console.log(err)
},
function(evt) {
// progress events
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}
)
queue.push(up)
}
$q.all(queue).then(
function (data) {
deferred.resolve(data)
},
function (err) {
deferred.reject(err)
}
)
return deferred.promise
}
This is, without any surprise, the confused output I get:
percent: 68 restfactory.js:359
percent: 100 restfactory.js:359
percent: 100 restfactory.js:359
percent: 14 restfactory.js:359
percent: 37 restfactory.js:359
percent: 52 restfactory.js:359
percent: 89 restfactory.js:359
percent: 100 restfactory.js:359
percent: 100 restfactory.js:359
Do you have any idea how could I manage to have something like:
file1 - percent: 68 restfactory.js:359
file1 - percent: 100 restfactory.js:359
file2 - percent: 100 restfactory.js:359