Link to home
Start Free TrialLog in
Avatar of lantervj
lantervjFlag for United States of America

asked on

cffile destination permission error

It appears that cffile does not have permission to write/upload a file to the server.

The following code works when I upload a file from my PC;
<cffile action="upload" destination="#request.ControlPath#documents\original\" mode="777" nameconflict="makeunique" filefield="docFile" accept="application/pdf,application/msword,application/,text/plain,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/,application/">

The following does not work when I upload a file I scanned using Dynamic Web Twain;
            <cfset dest = "#request.ControlPath#documents\original\">
            <cffile action="upload" filefield="RemoteFile"  mode="777" destination="#dest#" nameconflict="OVERWRITE" />

But it does work with dest="c:\"
Avatar of dgrafx
Flag of United States of America image

After scanning with dynamic web twain - where is the file?
Is it on the same machine as your website?

Do you then submit a form sending the twain file to your cffile?
That may be the issue - you need to submit a form when using cffile action=upload.
After reading my answer I see I left off that I was going to say you may want to use cffile action=move - because it is already on the same server so you are not uploading.
If it is not on the same server then you need to use cfftp and not cffile.

good luck
check your path

which is dest,

dump dest and see what you are getting. Afterupload are u checking the file exists with cffile.serverfile try that and see where it is wrong
One other thing to consider - CF needs permission to write to the target folder. If the target folder is anywhere on the network, CF won't have access to it as by default, it runs as local system.

To make a folder accessible in windows (guessing from the word, excel etc..)

1) create a user in AD call it "CFService" give it a stroing pwd that never expires
2) Go to services > CF App Server > Log On Tab and set it to the new user
3) go to target folder and give CFService perms
4) restart CF service

(also fyi mode="777" is only valid for *nix systems)
Avatar of lantervj


I think I'm having trouble with the return from the action page (for one thing).

WebTWAIN.HTTPUploadAllThroughPostASPDF("", "/control/documentHandler/actUploadScan.cfm", "Scan_<cfoutput>#users_info.lastname##indivnum#</cfoutput>.pdf");

if (WebTWAIN.ErrorCode != 0)                              //Failed to upload image
                        alert("error_fromActiveX: "+WebTWAIN.ErrorString+'   error code='+WebTWAIN.ErrorCode);
                        {                                                                                     //Successful

The WebTWAIN.ErrorString is HTTP Process error and the ErrorCode is 2003.  I have no idea what 2003 means but the ErrorString indicates

1. The write permission is not granted to the specified directory on the web server.

2. The action page is incorrect or returns something from Web server.

3. The Port for uploading is not right.

4. The size of the images you try to upload is beyond the maximum allowed size set on the server.

Since it's not a write permission problem and the port is correct and the size is not the problem, it must be that the action page is returning something. And it does.  It's all html.  I don't know how to stop that.
can you post the file where you have actUploadScan.cfm
there may be something we can see that will solve your error.

But after that's fixed I'm fairly confident that you are not wanting to upload the file as no form is being submitted.
You are actually wanting to simply move the file - or do you even need to move the file?
Once twain is working why not twain it right to it's final destination?

Anyway - post your actUploadScan.cfm code and we'll fix er up for ya!

            <cfset dest = "#request.ControlPath#documents\original">
            <cffile action="upload" filefield="RemoteFile" destination="#dest#" nameconflict="makeunique" accept="application/pdf,application/msword,application/,text/plain,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/,application/" />

      <cfcatch type="any">
            <cfif left(cfcatch.Message, 34)  eq "The MIME type of the uploaded file">
                  <cfset attributes.message = "The file you uploaded is not a valid format, please try again with a .pdf, .doc, .xls, pptx, or .txt file.">
                  <cfset attributes.message = "There was an error with the document file you uploaded<br />Please try again.">
Avatar of dgrafx
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sample code from Dynamic Web Twain:



<SCRIPT  LANGUAGE="javascript">
function btnScan_onclick()

function btnUpload_onclick()
      var strActionPage;
      var strHostIP;
      var CurrentPathName = unescape(location.pathname);      // get current PathName in plain ASCII      
      var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
      strActionPage = CurrentPath+"test_scan_upload.cfm"; //the ActionPage's file path
      strHostIP = "localhost";                   //the host's ip or name

  frmScan.DynamicWebTwain1.HTTPPort = 80;
  frmScan.DynamicWebTwain1.HTTPUploadAllThroughPostASPDF(strHostIP, strActionPage, "tscan2.pdf");

      if (frmScan.DynamicWebTwain1.ErrorCode != 0)                              //Failed to upload image
            alert("error_fromActiveX: "+frmScan.DynamicWebTwain1.ErrorString);
      else                                                                                          //Successful




<p align="center">
<b>Scan an image</b>
<OBJECT CLASSID = "clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
      <PARAM NAME="LPKPath" VALUE="DynamicWebTwain.lpk">

<form id="frmScan" action="scrap.cfm" enctype="multipart/form-data" method="post">
      <table width="100%">
      <object classid="clsid:FFC6F181-A5CF-4EC4-A441-093D7134FBF2" id="DynamicWebTwain1" width="250" height="350"
                  CodeBase = ",0">
               <param name="_cx" value="847">
               <param name="_cy" value="847">
              <param name="JpgQuality" value="80">
              <param name="Manufacturer" value="DynamSoft Corporation">
              <param name="ProductFamily" value="Dynamic Web TWAIN">
              <param name="ProductName" value="Dynamic Web TWAIN">
              <param name="VersionInfo" value="Dynamic Web TWAIN 5.0">
              <param name="TransferMode" value="0">
              <param name="BorderStyle" value="0">
              <param name="FTPUserName" value>
              <param name="FTPPassword" value>
              <param name="FTPPort" value="21">
              <param name="HTTPUserName" value>
              <param name="HTTPPassword" value>
              <param name="HTTPPort" value="80">
              <param name="ProxyServer" value>
              <param name="IfDisableSourceAfterAcquire" value="0">
              <param name="IfShowUI" value="-1">
              <param name="IfModalUI" value="-1">
              <param name="IfTiffMultiPage" value="0">
              <param name="IfThrowException" value="0">
              <param name="MaxImagesInBuffer" value="1">
              <param name="TIFFCompressionType" value="0">
              <param name="IfFitWindow" value="-1">
      <input type="button" value="Scan" ID = "btnScan" style="width: 100; height: 30" onclick='return btnScan_onclick()'>
      <input type="button" value="Upload" ID = "btnUpload" style="width: 100; height: 30" onclick='return btnUpload_onclick()'>



<cffile action="upload" filefield="RemoteFile" destination="c:\" nameconflict="OVERWRITE" />



<!-- Here you can code your results like, so and so doc has been uploaded blah blah blah! -->
in your first post you said that if you coded your destination to be "c:\" then everything worked ok - is that correct?
Is "users_info" valid when using webtwain?
Can you hard code something to see if the results vary.
Yes, c:\ works.  Yes, users_info is valid.  I've gone over and over their KB and sample code.
"#request.ControlPath#documents\original" is being used in both the original upload file function and the new upload scanned image function.  It still works perfectly in the upload file function.
OK, c:\ works and d:\ works.  Even d:\inetpub\wwwroot\\development\control\documents\original works.  But I need the variable to switch from the dev site and the production site. So, I have to come up with the absolute path.  Then I have to stop the post response.
Main cause of failure was the missing backslash at the end of the path.  Now I just have to stop the response html.
how do you mean "stop the post response"?
WebTWAIN.HTTPUploadAllThroughPostASPDF("", "/control/documentHandler/actUploadScan.cfm?indivnum=<cfoutput>#indivnum#</cfoutput>&docareaid=<cfoutput>#docareaid#</cfoutput>", "Scan_<cfoutput>#indivnum#_#users_info.lastname#</cfoutput>.pdf");
if (WebTWAIN.ErrorCode != 0)                              //Failed to upload image
        alert("error_fromActiveX: "+WebTWAIN.ErrorString+'   error     code='+WebTWAIN.ErrorCode);
            {                                                                                    //Successful

The two alerts for an error always come up because the action page returns a post response.  If it returns a response, WebTWAIN assumes it's an error.  The ResponseString is always html code.  For example, if there was an error (syntax, etc.) I get the html to display the error. Otherwise, I get the html of the page it returns to (which also gets interpreted as an error).

I'm trying to explain as best I can.  The mechanics are above me (I guess).

I'm going back to the WebTWAIN support people again.  It's just that they can't spell Coldfusion.
The HTTPUploadAllThroughPostASPDF function apparently submits the actUploadScan.cfm page.  It's that response that seems to be the trouble.
I guess i should ask again - isn't the file already on the server without needing to use cffile?
I don't know - just asking.
Try it without and see if the file does indeed get posted to the server.
The file is being uploaded to the server now.  I'm just getting error messages anyway.  So, I guess this ticket is closed.  I'l post another one for the rest of the problem.
are you saying that the file is posted to server without cffile?