0

Can we set the file path in javascript for

<input name="pictureUL" type="file" value="upload" onChange="this.form.submit()"/>

without opening the select file dialog box? I have 2 buttons SCAN and FIND. ADD button opens dialog box asking user to select the file which will be uploaded to the server. SCAN button has to scan the document and upload it to the server. Scanning is fine but to submit the form i need to set the file path in the file tag as i am submitting the form there. Is there a way to do it? Thanks in advance.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
user3334226
  • 151
  • 1
  • 5
  • 15
  • And let evil hacker page steal all your files? – Yuriy Galanter Apr 24 '14 at 20:37
  • You should post here a sample code snippet - reading your question I don't really know what is the problem. – dizzer Apr 24 '14 at 20:37
  • Do you mean scanning in the [Sandboxed FileSystem API](http://dev.w3.org/2009/dap/file-system/file-dir-sys.html) and how to upload from there? Because otherwise it is not possible. – t.niese Apr 24 '14 at 20:44

2 Answers2

1

Due to possibly security issues, modern browsers do not allow you to access the file path or modify the value of an <input type="file">. You also cannot view the file path, as it will display C:\fakepath\yourfilename.yourfilextension.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
0

You can't do it directly but you can create your new Filelist using a DataTransfer object, and if you wish you can copy your data into it to and create a duplicate with the specific change you want to make.

let file = new File([blob], fileName);
let list = new DataTransfer();
list.items.add(file);

You can then set it as the file attribute of the DOM node:

fileInput.files = myFileList;