file upload using AJAX
How do I upload a file using AJAX?
<form name="pic" id="pic" action="" method="post" enctype="multipart/form-data">
<input class="redField" type="file" name="file_upload" value="" size="20" maxlength="50" onBlur="sendPhotoNew(this.form)">
</form>
<script>
function sendPhotoNew(form){
var file=form.file_upload.value;
var e= new (images);
e.setForm('pic');
e.setHTTPMethod("POST");
var picNLink=e.photos_upload(file);
photo_new.innerHTML=picNLink[0];
$('#photo_new').show();
}
</script>
I know how do this using conventional forms.
I am getting the error
Invalid content type: application/x-www-form-urlencoded.The files upload action requires forms to use enctype=""multipart/form-data"". The specific sequence of files included or processed is: C:\inetpub\wwwroot\snip\images.cfc
Which I would expect if I didn't use the correct form header.
}
<cffunction name="photos_upload" access="remote" returnType="array">
<cfargument name="file" type="string" required="true" >
<cffile ACTION="UPLOAD"
DESTINATION="c:\inetpub\wwwroot\blahblah\coldfusion\images\images_folder\"
NAMECONFLICT="MAKEUNIQUE"
FILEFIELD="#arguments.file#"
accept="image/*, image/jpg, image/jpeg,image/png"
>
</cffunction>
