Note:
Below is an answer that reflects the status of outdated browsers in 2009. Now you can really set the value of the file input element dynamically / programmatically using JavaScript in 2017.
See the answer in this question for more information, as well as a demo:
How to set the value of a file input programmatically (for example: when dragging files)?
I need to do this in order to programmatically send a POST request to a service from javascript code from an application using .NET WebBrowser, which is basically built-in Internet Explorer. For this service, one of the fields must be a “file”.
So, is there a way to set the value of the “file” in the form, given that I have the content of the file, for example, in an array of bytes (and not the path to the file, I'm not trying to steal files from users here :)).
Or perhaps a way to explicitly create and send a POST request instead of dynamically creating a FORM?
I need to use the JavaScript code that will run in mine WebBrowser(think IE). Is it possible?
source
share