angular-evaporate
angular-evaporate copied to clipboard
$dequeueAll does not clear Evaporate.filesInProcess
I am wrapping angular-evaporate in a service in my app and my service provides the following methods:
singleton.startNextUpload = function () {
// group is a custom attribute I set on the upload before passing it to
// aeQueue.$enqueue
var group = aeQueue.$uploads[0].group;
// our use case requires that our signer endpoint uses unique aws credentials
// for every groupId. The signer endpoint determines which secret key to use
// based on the supplied groupId argument
aeQueue.config.aws_key = group.awsAccessKeyId;
aeQueue.config.signParams = {
groupId: group.id
};
aeQueue.$uploads[0].$start();
};
singleton.cancelAllUploads = function () {
aeQueue.$cancelAll();
aeQueue.$dequeueAll();
...
};
aeQueue
above is an instance of AngularEvaporate. I noticed that if I call my cancelAllUploads
method above while an upload is in progress, subsequent file uploads started by startNextUpload
will fail the AWS signature check. After much debuging, I discovered that it was because AngularEvaporate is passing the groupId
of one of the supposedly dequeued uploads, instead of the group ID set on the signParams
in startNextUpload
.
I noticed that AngularEvaporate contains a filesInProcess
property that it inherits from Evaporate and that it still contained references to the uploads that should have been dequeued. My guess is that these uploads somehow conflict with the uploads stored in AngularEvaporate's $uploads queue, causing the wrong signerParams to be used on subsequent uploads. I modified my cancelAllUploads
method to this:
singleton.cancelAllUploads = function () {
aeQueue.$cancelAll();
aeQueue.$dequeueAll();
aeQueue.cancel(); // inherited from EvaporateJS
...
}
The call to cancel
clears the filesInProcess
array and now subsequent uploads work correctly.
My recommendation is that $dequeueAll
should also clear the filesInProcess
property
First of all, thanks for the detailed explanation! One question so far: which version of Evaporate
are you using (1.x or 2.x)?
No problem! I am using Evaporate 1.6.4. I saw the other feature request issue stating Evaporate 2.x is not yet supported