addFiles bug #1398

Closed
jardakotesovec opened this Issue Apr 21, 2015 · 10 comments

Projects

None yet

2 participants

@jardakotesovec

I was trying to do following

        uploader.addFiles([event.target]);

And end up with:

Uncaught TypeError: Cannot read property '_handleNewFile' of undefined

I think problem is in this code:

                        qq.each(files, function(idx, file) {
                            this._handleNewFile(file, batchId, verifiedFiles);
                        });

Because this is not defined inside each.

So I tried passing FileList which also should be valid input:

        uploader.addFiles([event.target.files]);

But also does not like it:

[Fine Uploader 5.2.0] [object FileList] is not a valid file container!  Ignoring!

And finally using worked ok:

uploader.addFiles([event.target.files[0]]);

But two previous inputs also should be valid.. or Am I missing something?
Using latest FineUploaderBasic 5.2.0

@rnicholus
Member

It looks like you are trying to pass in an array of an array, which is definitely not valid.

@rnicholus rnicholus closed this Apr 21, 2015
@jardakotesovec

Thanks for response.

In first case uploader.addFiles([event.target]); target is not array:

console.log(event.target)
<input type=​"file" data-reactid=​".e.1.0.0.2.0.2.1.0.0.1.1">​

In second case uploader.addFiles([event.target.files]); files is also not array, but FileList object:

console.log(event.target.files)
FileList {0: File, length: 1, item: function}

And according to docs input should be array of inputs or fileLists or ... .

@rnicholus
Member

A FileList is a pseudo-array, and an array of an array is not an acceptable value for this method. The docs do seem to suggest that this is acceptable, but that is a typo. I'll update the docs to clarify how FileList should be passed.

It does look like there is one bug here - file input elements cannot be passed into addFiles. This is an uncovered area of our unit tests at the moment (passing in file inputs). I'll fix this and release a hotfix release probably today or tomorrow at the latest.

@rnicholus rnicholus reopened this Apr 21, 2015
@rnicholus rnicholus added this to the 5.2.1 milestone Apr 21, 2015
@jardakotesovec

Ok, makes sense. Thanks!

@rnicholus
Member

Just to clarify, should pass in the raw FileList by itself, not inside of another array. I'll fix the issue with passing in an next.

On Tue, Apr 21, 2015 at 8:17 AM, Jarda Kotěšovec notifications@github.com
wrote:

Ok, makes sense. Thanks!

Reply to this email directly or view it on GitHub:
#1398 (comment)

@rnicholus
Member

Note that this bug only applies to <input type="file"> elements passed into addFiles on browsers with File API support. Older browsers are unaffected. It looks like this particular issue has been in place since 5.1.0 and was introduced in eb5b396 during work on #1198.

@rnicholus rnicholus closed this in 9e91f4f Apr 21, 2015
@rnicholus
Member

Fixed in 5.2.1 (just released). I'll update the blog, download page, and npm shortly.

@rnicholus rnicholus added a commit that referenced this issue Apr 21, 2015
@rnicholus rnicholus chore(build): update after 5.2.1 release
#1398
[skip ci]
d5dac3f
@rnicholus
Member

Everything has been updated. Thanks for the report.

@rnicholus rnicholus added 5 - Done and removed 3 - Doing labels Apr 21, 2015
@jardakotesovec

Impressed with such support 👍 .

@rnicholus
Member

We aim to please. I added a unit test for this code path as well to hopefully prevent this from happening again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment