I have a question regarding upload a file to some server. I understand that due to security issues, web browser does not allow javascript to access user's file directory. So currently my method is to add a choose file button and manually choose a file to upload. I did a lot of research on internet for other alternate approach, but did not find anything useful. Is there any possible way to automate the process of choosing the file? (I only need to upload one file) Like changing web browser setting or attach this file somewhere inside html or any other approach?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
I'm sorry to say but I have tried this in the past and the web-browser does not allow it to be done due to security. Even if you know the filename on the user's computer, the browser will only attach a file object to your
<input type="file" />
element if it was selected via the web-browser's native 'file browser'. Although this is bad news, this is the right answer.The security issue is that web-browsers enforce the rule that the user must be informed and also initiate the action of the file being attached to form elements in the web-page they are viewing.
This action can only be initiated by the user via the default 'browse' button on the
<input type="file" />
element or a file drag/drop action by the user captured with javascript.