I think you need to consider the actual timing of following two things.
1) The timing of the 'filePicker' HTML DOM Element is generated
2) The timing of the code you've written is executed
I'm not sure where you've written the code, but if the 2) happens before 1) is executed, you'll get an error.
For example, if you'll put the code into the onAfterRendering method of the view controller and the 'filePicker' is in the view, possibly you can execute the one without problem.
Regards,
Makoto