I need to upload a picture from PC to a website that uses drag and drop interface. I am using Javascript to open the necessary link, set properties and click to the upload field. But then a file manager pops up with a window where I need to choose a file from my filesystem. I cannot use Javascript here anymore. How can I automatize this? Somehow I need to upload a picture and then click send button using javascript.
P.S. I am not trying to implement drag and drop box, I need to use it.
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
If this website is not yours, you cannot automate this with JavaScript. It’s an security aspect that an user interaction is required for uploads via browser.
The FileList object is read only.
If it is your website, you could set for example a fix file name to upload or use a more powerful language than JavaScript – like python.
Use a user script for example with Tampermonkey:
https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
Bind to the
change
event on the file input on your site of interest. Once it’s fired, use DOM’sHTMLElement::click()
function to submit your upload automatically