So, I’m idly musing about an AJAX-based S3 file manager and it occurs to me: I don’t know how to do file uploads via AJAX PUT requests. Is there any way to get access to a local file selected in an input element in a form? That’d sure make a nice alternative to pasting data into a big textarea.
-
About Me
Hi there! My name is Leslie Michael Orchard. I'm a serially enthusiastic, caffeine-dependent {web,mad,computer} scientist and {tech,scifi} writer working for the Mozilla Corporation and living near Ann Arbor / Detroit in Michigan.
-
Search
-
Buy my books
-
Related Posts
Most Commented Posts
- July 3, 2008 Getting Laconica up and running (90)
- June 16, 2008 Firefox 3 Download Day Mega Widget (56)
- December 3, 2004 If you snore, get tested for sleep apnea. Now. (41)
- March 4, 2003 Oh, I’m feeling lucky. (35)
- June 17, 2005 We’re engaged! (32)
- April 25, 2006 A Honeymoon in San Francisco (27)
- August 17, 2006 Don’t ask me who I am (24)
-
Tags
aggregators ajax apple atom books delicious entertainment feedmagick feeds firefox gaming hacking hacks identity ipod javascript js json links mashups metablogging microformats mozilla opml osx outliners php podcasting python rss scifi software syndication twitter web20 webdev webservices wordpress wow writing xml xoxo xoxooutliner xsl yahoo -
Recent readers
-
Archives
- April 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- February 2004
- December 2003
- November 2003
- October 2003
- September 2003
- August 2003
- July 2003
- June 2003
- May 2003
- April 2003
- March 2003
- February 2003
- January 2003
- December 2002
- November 2002
- October 2002
- September 2002
- August 2002
- July 2002
- June 2002
- May 2002
- April 2002
- March 2002
- February 2002




10 Comments
I’ve yet to find a way to automate an http file upload within the browser. You can’t write to the builtin file upload input element’s filename. Possibly a Flash helper would be of use - see http://www.aflax.org for instance.
btw - I’ve sent some emails to your pobox addr lately with no ack. Either I’m a bit stinky or you’re not getting them or a bit of both.
I don’t think that you can do that right now, but read-only access to the file pointed to by a file upload element sounds like a good thing to propose to the WHATWG people for inclusion in their Web Applications spec, if it isn’t already there.
As long as it’s read-only and you can’t actually put a filename into that box from script I don’t really see any security flaw to that.
gmail is AJAXing up attachments already. I don’t really know how they’re pulling it off.
i’m not sure gmail is ajaxing attachments, i think they’re using a clever combination of iframes and dom manipulation of the input boxes, with perhaps a javascript timer auto-triggered onsubmit().
just guessing there, but i think you can see it if you have a “view rendered source” plugin for your browser…
No way to do it in a browser using the current technologies - without changing security restrictions, etc. I did implement an “AJAX style” uploader using ActiveX to browse for a file, base64 encode it and then post it to the server using the XHR object - this was before “AJAX”, but not brain surgery, of course you did have to let IE trust the site to allow the ActiveX stuff access to your hard drive - could’ve signed it I guess, but too much trouble for an Intranet app. GMail is just use an auto submit when you choose a file; in IE they are using a little bit of JS to auto popup the dialog box so you don’t have to have a browse button visable. The AFLAX stuff looks interesting, though.
Gmail does not use ajax to upload files. This link shows how we can upload files the way gmail does:
http://blog.360.yahoo.com/blog-qCsFWG45eqF9lZ05AZldsUC.?p=58
I just hit the wall with the same problem.
My current idea is the following:
- Open a popunder (not to make it annoyingly visible)
- set this window as receiver to the form
- trigger a submit by javascript parallel to the Ajax request
- after upload the popunder can call a jS function in the opener page that talks to the server and receives the uploaded pic for example
- then the popunder closes itself
Could this be a solution?
ellinas:
Most AJAX file upload solutions work almost exactly as you describe, however they use an invisible iFrame instead of a brand new window.
For example, the upload_progress plug-in for Ruby on Rails uses this method to provide upload progress in real time.
The invisible IFrame works great. I have a script that has suited me fine. You can see it at http://www.seemysites.net/projFolder/uploader - it’s completely free, too.
Nope, the iframe approach won’t work for Amazon S3 - which is what this post is really looking for. I’m looking for a 100% client-side solution that uses Amazon’s S3 api. So, no form post uploads, no server-side PHP helpers, just browser-to-S3 HTTP PUT. I don’t think it’s presently possible.