Copy link to clipboard
Copied
Hi,
I am trying to upload a file with ajax, is there a way to do this using cfajaxproxy or any of the other ajax controls? I usually use uploadify but is not really doing the job in this case.
<cfform>
<h4>Document Title</h4>
<input name="docTitle" id="linkTitle" />
<h4>Document</h4>
<input type="file" name="document" id="document" />
<a href="javascript:submitDoc()">upload document</a>
</cfform>
Thanks,
H.
Copy link to clipboard
Copied
As far as I know, XMLHttpRequest can't handle multipart/formdata, so there's no strictly AJAX way to do it. The CF docs even specify that this is not possible using ajaxproxy's "setform" function:
"Note: You cannot use the setForm function to submit the contents of file fields." (ref)
You can, however, use a hidden iFrame to handle the file uploading, monitor it, and then return the results to your application. I've used this before, and it works well.
Ray Camden has a pretty good article on this..check it out:
http://www.coldfusionjedi.com/index.cfm/2008/2/27/Can-you-do-file-uploads-with-ColdFusion-8s-Ajax-features
Hope this helps--regards