Topic: addFile from one uploader to another
I'm trying to do something. I'll start with some code and then a more detailed explanation of the problem:
// binded to FilesAdded on an uploader:
function onFilesAdded(upload, files) {
files.forEach(function(file) {
getS3Info(upload, file);
};
return false;
}
function getS3Info(upload, file) {
$.getJSON(myUrl,
{ filename: file.name, tokenId: someTokenId }
function(extraData) {
uploadToS3(upload, file, extraData);
});
}
function uploadToS3(uploader, file, extraData) {
file.s3data = extraData;
uploader.removeFile(file);
s3uploader.addFile(file); // (THIS IS THE INTERESTING POINT)
s3uploader.start();
}
// binded to FilesAdded on a certain the s3uploader:
function onS3FilesAdded(upload, files) {
console.log("configure the extra S3 params");
// simply do a upload.settings.multipart_params = { ... }; using file.s3data
}
That is, I'm trying to upload to Amazon S3 but I have to get the AWSAccessKeyId, signature, etc, dynamically for each file that's added.
So, my idea was this: use one plupload for user file selection and a second plupload to actually make the upload to S3 when I do have all the auth data for that file. The user facing plupload won't ever be .start()ed and instead I just use to queue the files. Then call my own server to get the authorization data and when I get it back, then move the file with the additional parameters to the "real" uploader, s3uploader.
Things have been going well up until the point of calling s3upload.addFile(file); I have checked that file is indeed a plupload.file instance and s3upload seems also correct, but when I call addFile it doesn't seem to add the file at all. Not only does onS3FilesAdded not get called, but if I look into s3upload.files it is indeed empty.
So, the basic question is can addFile work this way? How?
Alternatively, if it is not possible to use addFile like this, would it be possible in any other way to have per file control of the upload so that I can delay the upload until I actually have the S3 auth data?
Thank you very much for any help you can give me.