1 (edited by gbrachi 2015-12-14 10:08:35)

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) {
                { filename: file.name, tokenId: someTokenId }
                function(extraData) {
                    uploadToS3(upload, file, extraData);
    function uploadToS3(uploader, file, extraData) {
        file.s3data = extraData;
        s3uploader.addFile(file); // (THIS IS THE INTERESTING POINT)
    // 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.

Re: addFile from one uploader to another

Likely not due to security constraints.

If you're utilizing the html4/5 runtime (native browser) to upload, then the actual file selection, consuming the raw bytes of the selected file into memory and transmitting is internally handled by the browser. The file dialog may be invoked by a trigger click event against the input type=file, but reading the file from the drive is still managed by the browser. Flash/Flex and the other runtimes are even more locked down, the File Dialog has to be invoked by a click event from on or within the Flash/Silverlight object.

JavaScript can read the absolute path value off of a input type=file DOM element, but it cannot set the path into the element.

Operating without these security constraints, would be a trojan horse out of the box. Either the browser natively or Flash/Silverlight could be directed to just scan whatever path/file off an end-user's machine or network and transmitted in the background without their knowledge. Which would not benefit legit businesses.

Re: addFile from one uploader to another

Yeah, pretty much what I thought. Thanks.

I'll be forced to find some way to have a per file control of the queue, I guess.