0

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.

eqiz
  • 1,409
  • 5
  • 24
  • 45
  • Web browsers won't allow you to do this, instead you can choose standalone applications like `Task Schedular` & `outlook` for this task. –  Dec 12 '14 at 04:59
  • I'm confused by what you mean. The webpage itself and the javascript and everything is already doing what it needs to do to actually upload the images etc. All I'm wanting to do is pass the data to the input directly so when it then does its next "call" to its own javascript to upload the file then it will be triggered. – eqiz Dec 12 '14 at 05:13
  • You can not set file input values that is a security precaution. Why don't you just schedule a task, that way the boss does not even need to click a button. That is normally how automation works. – epascarello Dec 12 '14 at 05:24
  • @eqiz, tell me are those images dynamic? –  Dec 12 '14 at 05:26
  • perhaps look at something that allows drag drop uploading of images (this significantly reduces the time it takes to select and upload files in my experience). http://www.dropzonejs.com/ you may need to update your upload code to allow multiple file uploads – haxxxton Dec 12 '14 at 05:26
  • @Arvind they are dynamic images that are always different if thats what you mean. its not our code so we can't manipulate it. We work under a franchise so we can't manipulate the original code, so doing a Calendar task item or something like that isn't possible. We have to submit the images through the page. – eqiz Dec 12 '14 at 05:42
  • Either do it by drag-drop or if you have the image by other means already (_Object_ Reference in _JavaScript_ to a `` or something) you'd have to do it completely in _AJAX_ – Paul S. Dec 13 '14 at 00:52

1 Answers1

0

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.

Community
  • 1
  • 1
James Westman
  • 2,468
  • 1
  • 14
  • 19
  • Well technically you are trying to save data from a local source without them knowing. I can see what you mean why this may be impossible because it could be seen as a "Security" issue, but If i'm wanting to just upload an existing file from another website that wouldn't invoke any type of local file request. – eqiz Dec 15 '14 at 01:48