2

I'm using FineUploader and I'd love to be able to programmatically trigger the file browser. I imagine something like this:

uploader.fineUploader('browseFiles');

Unfortunately I couldn't find anything like that around the interwebs. Ideas?

EDIT

Tried the following as suggested but the file browser is not triggered :( The issue seems to be that this would call the click event handler defined by the developer (which, in my case, doesn't exist), not the one defined by FineUploader.

$('.qq-upload-button-selector').click();
$('.qq-upload-file-selector').click();
$('.qq-upload-filename-selector').click();
$('.qq-edit-filename-selector').click();
$('.qq-upload-file').click();
$('input[type="file"]').click();
Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
ios-lizard
  • 834
  • 1
  • 12
  • 19
  • 1
    possible duplicate of [Programmatically trigger "select file" dialog box](http://stackoverflow.com/questions/8595389/programmatically-trigger-select-file-dialog-box) – Mark Feltner Mar 05 '14 at 13:35
  • I've tried to apply the technique used in the link you posted but unfortunately I couldn't make it work (see edited question) – ios-lizard Mar 05 '14 at 19:07
  • There is no technique, just the absence of one. – Mark Feltner Mar 05 '14 at 19:34

3 Answers3

2

$('input[name="qqfile"]').click();

The input file control is initialized with default name "qqfile". You may look up the source code or inspect the input element by using the Chrome DevTool. It is simpler way to trigger the file window. The relevant source code are shown below by imaging. Initialize the options.

Create the element of input file.

Cliff Liu
  • 186
  • 1
  • 6
1

There is not a reliable, working, and cross-browser way to initiate the file browser dialog programmatically. A quick search around the internet for programmatically clicking an input element shows this is true:

Programmatically trigger "select file" dialog box

jQuery : simulating a click on a <input type="file" /> doesn't work in Firefox?

This is because programmatically opening the file browser would be extremely risky and open the door for malicious sites to trick users into uploading their data unknowingly.

Community
  • 1
  • 1
Mark Feltner
  • 2,041
  • 1
  • 12
  • 23
  • Thanks for your answer. Unfortunately I do not think I can apply these to FineUploader. I was wondering whether there is something specific to FineUploader (it seems like there should be, no?). Thanks again – ios-lizard Mar 05 '14 at 18:50
  • 1
    The point of this answer is that there is no way to do this reliably due to browser-specific restrictions, and you should rethink your design if this is a requirement. – Ray Nicholus Mar 05 '14 at 19:20
0
$('input[type="file"]').click();

works OK in my web with fine uploader (tested with IE, Chrome, and Firefox).

Pang
  • 9,564
  • 146
  • 81
  • 122
Danus
  • 1
  • 1