Copy link to clipboard
Copied
Hello,
environment: cf8 (win); no db;
I'm trying to pass the form scoped refernce to a method that uses cffile to upload a file. My understanding with cffile is that the form field needs to be passed to the method as scoped as a form struct in order to get the file to upload (otherwise i get a enctype error). Is it possible to pass the form through the javascript object reference to the cfc? (serializing the form doesn't seem to work)
sample code;
<cfajaxproxy cfc="name" jsclassname="jsNews" />
...
<script>
function fnSetNews(id){
var cfc = new jsNews();
file=$('#file_'+id).val();---not quite sure how to call; I would prefer to keep the script on a .js file (no fancy cf referencing)
var response=cfc.setImage(file);
/*file is a valid form path selected on a "file" field of a form.*/
}
</script>
...
<form id="unique" class="frmUpload">
<input type="file" name="unique" id="unique" />
<input type="submit" value="go" />
</form>
...
listener (calls the js function upon submit)
$('.frmUpload').livequery('submit',function(event){fnSetNews(this.id);return false;});
...
cfc code:
<cffunction name="setImage" access="package" output="true" returntype="Any">
<cfargument name="fileField">
<cffile action="upload" filefield="#ARGUMENTS.fileField#" destination="validPath" nameconflict="overwrite">
</cffunction>
any help is greatly appreciated-dj
Copy link to clipboard
Copied
I am not sure what are you trying to do.
But your question sure sounds like you do not understand how HTTP forms and file uploads work.
With a normal HTTP form request.
Now what exactly do you want to do with JavaScript in that process?
Copy link to clipboard
Copied
i am trying to upload a picture using a remote call to a cfc. via the cfajaxproxy. the problem seems to be that you need to post the file in order to upload the attached link and I can't get the form struct inside of the cfc to do the upload. i can get it to work if i call a cfm page but wanted to go with a purely cfc solution.
thnx-dj
Copy link to clipboard
Copied
i have also since learned that the file field is not displayed on the form when i cfdump after it has been submitted. It's very odd but when i cfdump the form after it has been submitted, it shows all the fields minus the file field. I load the form using ajax (it isn't on the page when the document.ready() function starts.... is that why the file field doesn't show up when i submit the form? i've tested other ways of creating the form, it seems that if the form is generated at load time, that the file fields exist when i cfdump. -confused; dj
Copy link to clipboard
Copied
You MAY be encountering security issues with file forms controls in the browser. I'm not sure what you have tried and I have not done much with file upload control dynamic generation, but I know I have done some. But you are definitely skirting along the edge of allowed behavior. There are intentionally limitations to try and protect users from bad programmers who would try and use DHTML and AJAX functionality to trick people into uploading sensitive information form their computers in drive by attacks.
I would tackle this in two parts. Which it sounds like you may have done. But I would first make the CFC and test it to show it works form a static form. I would then develop the front end and make sure it submits the data properly with things like HTTP live headers as well as simple back end processing. Then I would tie the two pieces together and test to work out the bugs.