skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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’s HTMLElement::click() function to submit your upload automatically

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search