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. I just can't find anything on how I can do this...
Any help would be appreciated!
thnx,
Christoph