Home > front end >  Automatically choose file for website upload based on last submission?
Automatically choose file for website upload based on last submission?

Time:10-17

So, I am on a enter image description here

CodePudding user response:

Unfortunately JS can't help here. For security reasons, it is not possible to manually add and upload a file in a file input control with JavaScript.

The reason behind this is that webpages would be able to upload files from someone's computer, so long as they knew the path.

What you could do as a last resort would be using a third party software that would register mouse clicks for you and emulate a real user acting on the interface.

CodePudding user response:

You cannot do that since this input type cannot be prefilled, here is a trick though :

What you can do is having an hiden collection of text inputs containing the base64 of the files you load using your form.

When a user selects a file, just use btoa() and atob() methods to base64-it and store it in this hidden form input

If you want to 'preset' some files, just fill your list of base64 and simply display a kind of placeholder to show that you have a file 'already appended'

Then in your script when form is submitted, work with the list of base64 instead of the actual values from the input type file

  • Related