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.

3
  • And let evil hacker page steal all your files? Commented Apr 24, 2014 at 20:37
  • You should post here a sample code snippet - reading your question I don't really know what is the problem. Commented Apr 24, 2014 at 20:37
  • Do you mean scanning in the Sandboxed FileSystem API and how to upload from there? Because otherwise it is not possible. Commented Apr 24, 2014 at 20:44

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.