0

Due to some reason, I would like to upload a file, lets say an image from url or a base64 string of photo, to the element with java script only. I would like to add this picture to the element automatically when my client preform some action. Is it possible to add a file without my client pressing the "choose file" button? I would like to keep the element. Submitting the file to server is not the difficulty. Should I do something like e.target.files/document.queryselector(id of input).files = (file path or the base64 string) ?

user13641224
  • 161
  • 1
  • 9
  • You mean, you want to upload my \user\passwords.dat without me selecting it? You can add a dynamically generated file on the client, but not a file from the file input – mplungjan Nov 05 '20 at 10:30
  • @mplungjan — They did say that file was an image from a URL or a base64 string. – Quentin Nov 05 '20 at 10:31
  • And I said, you cannot get that from a file input field - they need a blob or so – mplungjan Nov 05 '20 at 10:32
  • What's that _some reason_? What does happen after the file is in `FileList`? You might not need to hack into the Web APIs that deep. – Adam Azad Nov 05 '20 at 10:32
  • For security reasons, you have absolutely no access to programmatic fill a file input. – Squiggs. Nov 05 '20 at 10:34
  • You could just send that content independently. For example if it is a form, simply learn about [`hidden`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden) – tevemadar Nov 05 '20 at 10:35
  • @mplungjan that's some smelly jQuery hell you found for dupe. – tevemadar Nov 05 '20 at 10:38
  • @tevemadar There are more than one answer there – mplungjan Nov 05 '20 at 10:40

0 Answers0