简体   繁体   中英

Input/Pass an Image into an input type=“filename” directly from Javascript

I'm trying to pass files directly to an input type="filename" control element so I don't have to manually click [browse] and search for a file. I'm not trying to bypass any type of security or anything like that, i'm just trying to "imitate" the clicking of the browse putting and selecting an image without actually having to search for the file in the BROWSE FOR FILES dialog.

I'm wanting to do this directly through javascript.

Now some of you may be wondering "why the crap are you trying to do that?" well my employer has a website that he has to upload images of daily reports to and they use the standard

<input type="hidden" name="fileInput">

He wanted me to try and make a program that just does it for him and will just auto upload the files for him and all he has to do is hit submit at the end.

Is this possible?

EDIT#

I was thinking I needed to pass it the image in raw data:image/jpeg;base64 then pass it to the control somehow?

EDIT#2

What about doing something like

javascript:(function() { document.forms[0].file.value+='" + theFile + "';})()

Edit#3

From what I been looking into I guess the only possible thing is to try and do a straight HTTP Post with a MultiPart Entity. I guess this is the only way to go about doing it and its impossible to do anything directly from Javascript itself.

Would figure that since is considered a HTML object that javascript would be able to touch it. Kinda of weird that you can't.

This is similar to another question I answered recently. Basically, it is not possible. Even though you aren't trying to bypass security, it could be used to bypass security. Any and every time a webpage wants to access your files, the user must be alerted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM