1

Say I have an html page with a form for posting. The form is intended to post a file to my server, and to this end currently uses a <input type="file" name="attachment" ...> tag to attach this file data. However, what if I want to programmatically attach this file data instead of manually browsing on my local machine?

Say for instance I have the raw file data in text format for a file and I want to attach that to the form. I've tried things along the lines of

<input type="hidden" name="attachment" value=myRawFileData ...>

However when an <input type="file"> is submitted with the form there are two attributes filename and Content-Type that show up in the post, and when I use the method mentioned above the only attribute that appears is the name="attachment" one. So I'm assuming these are specific to the whatever html File object is being attached through the type="file" attribute. Is there a way to attach a hmtl "file object" without using type="file" and browsing on the local machine?

Dangerbunny
  • 81
  • 1
  • 3
  • 10
  • Why not have them fill out the form with whatever data you need from the user, post that data to the server, then pick up the "raw file data" from the database (or wherever you have it) and write the file to the server? – Adrian J. Moreno Jul 17 '13 at 22:41
  • If I understand what you are asking, if that was possible, any html page that I browse over, could pick up and send files from my PC to the web server without my knowledge. So I hope the answer is `NO YOU CANNOT`. When you use the type="file" field at least the user sees what is happening and is involved in the process giving their consent. – RiggsFolly Jul 17 '13 at 23:10
  • @RiggsFolly you can't, don't worry: http://stackoverflow.com/questions/16365668/pre-populate-html-form-file-input – kennypu Jul 18 '13 at 00:43

0 Answers0