1 (edited by Christoph 2017-11-03 19:01:23)

Topic: 2.3.5 - Programatically add files

I'm trying to upgrade from 1.5.x and I'm having an issue with programmatically adding files to the queue.  Previously, the following code worked:

        uploader.trigger("AddFiles", event.dataTransfer.files);

But the "AddFiles" event (previously part of plupload.html5.js) doesn't appear to exist any more.  I've tried other events (e.g., "FileFiltered") and the .addFile() method but nothing seems to work.  What's odd with the .addFile() option is that when it gets in to .resolveFile() it ends up in the else:

        else if (plupload.inArray(type, ['file', 'blob']) !== -1) {

and it instantiates a new file passing in null as the first argument.  Problem is when it gets back in to resolveFile(), ruid is null and the file isn't processed. 

Am I doing something wrong?  Is there a better/different way that I should be programmatically adding files to the queue?

EDIT: I'm trying to add the files as part of a drop handler for an element.  Here is how I have it set up (trimmed down a lot):

        var dropHandler = function (event) {
          var droppedFiles = event.originalEvent.dataTransfer.files;

          Object.keys(droppedFiles).forEach(function (mFileNum) {
            var oFile = droppedFiles[mFileNum];

            uploader.addFile(oFile);
          });
        }

        $('.validDropZone')
          .on('drop', dropHandler);

For reference, the file I've been doing my testing with is as follows (as displayed in Chrome's javascript console)

File {name: "Haunted Forest.jpg", lastModified: 1501758919000, lastModifiedDate: Thu Aug 03 2017 07:15:19 GMT-0400 (EDT), webkitRelativePath: "", size: 68142, …}
lastModified:1501758919000
lastModifiedDate:Thu Aug 03 2017 07:15:19 GMT-0400 (EDT) {}
name:"Haunted Forest.jpg"
size:68142
type:"image/jpeg"
webkitRelativePath:""
__proto__:File

The reason I'm doing this this with jQuery's .on('dop'), as opposed to using the ``drop_element`` option is because I have multiple drop zones on the page.


Now, in version 1.5.x, where I iterate through the dropped files in the code above, I instead just called:

        uploader.trigger("AddFiles", droppedFiles);

and that worked.  But now that event is gone and I need to figure out another way to do this.  But what I've tried so far has not worked. sad  I just can't find anything on how I can do this...

Any help would be appreciated!

thnx,
Christoph

Re: 2.3.5 - Programatically add files

It looks like what's happening, at least in part, is the getRUID(); function isn't returning a valid ruid because the file that it's processing (what was dropped and handled via jQuery) isn't what is expected (i.e., both fileInputs and fileDrops are both empty)...?  I'm guessing?

thnx,
Christoph

Re: 2.3.5 - Programatically add files

So it turns out that the control is not getting initialized.   It's dying out around line 1879 of plupload.dev.js (using that one for now while I try to upgrade our stuff from plupload 1.5.6).  Because I am not defining either the browse_button or the drop_element, it's dying out here.  But the thing is, I don't need either one of those.  As can be seen in the code above, I am (or was in 1.5.6) manually adding the files to the queue.  Is this just something that can't be done?  I *have* to have either the browse_button or the drop_element?  Bearing in mind I have multiple drop elements and don't want (or need, at least in 1.5.6) to instantiate muliple Uploaders.

Help?

thnx,
Christoph