• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Issue with CFUpload and CFCs

Explorer ,
Mar 07, 2007 Mar 07, 2007

Copy link to clipboard

Copied

I have the following two methods in the same cfc:

This function is used to generate the upload form...
<cffunction name="uploadPictureView" hint="Form to upload bio picture" access="remote">
<form name="uploadForm" action="cmsBios.cfc?method=uploadPicture" enctype="multipart/form-data">
Please Select Bio Photo<br>
<input type="file" name="UploadFile">
<input type="submit" value=" Upload File ">
</form>
</cffunction>

This function is used to upload the file to the directory and then close the popup and refresh the base page...
<cffunction name="uploadPicture" hint="Script to upload bio picture" description="Upload Picture" access="remote" output="false">
<cfset uploadPath = #APPLICATION.localPath# & "\images\bioPicts\">
<cfif not DirectoryExists(uploadPath)>
<cfdirectory action="create" directory="#uploadPath#">
</cfif>
<cffile action="upload" fileField="UploadFile" destination="#uploadPath#" nameConflict="MakeUnique">
<script>
refreshParent();
</script>
</cffunction>

The file does not get uploaded and instead it loads a description of the cfc and all the methods. No error so I can't tell what is wrong. How do I get this to work? Anyone have any ideas?

Thanks,

Jason
TOPICS
Advanced techniques

Views

482

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 07, 2007 Mar 07, 2007

Copy link to clipboard

Copied

The file does not get uploaded and instead it loads a description of the
cfc and all the methods. No error so I can't tell what is wrong. How
do I get this to work? Anyone have any ideas?


If you are getting the description of the CFC and it's methods, then CF
is running the Component Explorer, which is the default behavior if one
access a CFC directly with an URL.

When I use a CFC as an action for a post form, I put the method in as a
hidden field rather then an URL parameter. You could give that a try.

<input type="hidden" name="method" value="uploadPicture">


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 07, 2007 Mar 07, 2007

Copy link to clipboard

Copied

I removed the ?method=uploadPicture from the action attribute and added the hidden variable but now I am getting this message:

Invalid content type: "".

CFFILE action="upload" requires forms to use enctype="multipart/form-data".

The error occurred in D:\www\CMS\CFCs\cmsBios.cfc: line 511

509 : <cfdirectory action="create" directory="#uploadPath#">
510 : </cfif>
511 : <cffile action="upload" fileField="UploadFile" destination="#uploadPath#" nameConflict="MakeUnique">
512 : <script>
513 : refreshParent();

I have the enctype set to multipart/form-data. Also does the cfc know which method to use automatically from the hidden variable or do I need to specify that some how?

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 07, 2007 Mar 07, 2007

Copy link to clipboard

Copied

LATEST
Also does the cfc know which method to use automatically from the hidden
variable or do I need to specify that some how?

You have to specify the method you want to use as the value of the
hidden field.

<input type="hidden" name="method" value="methodName">

Look at the source of the form being generated by your code. Is it
properly formated? Is there a chance that somehow the output is mangled
so that you are not getting a correct form?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation