Skip to main content
Participating Frequently
June 16, 2021
Question

Image Uploads - Migrating to new server

  • June 16, 2021
  • 3 replies
  • 754 views

Migating to a new server, and getting an error when uploading a new photo.  Any help appreciated.   Here is my code:

<cffile action="upload" filefield="Photo" destination="#ExpandPath ('../images/temp/')#" nameconflict="MakeUnique">
<cfset Photo = File.ServerFile>
<cfset NEWPHOTONAME = 'VE_' & '#dateformat(now(), 'yyyy_mm_dd_')#' & '#timeformat(now(), 'hh_mm_ss_')#' & '#photo#'>
<cffile action="rename" source ="#ExpandPath ('../images/temp/#photo#')#" destination="#ExpandPath ('../images/original/#NEWPHOTONAME#')#">
<cfset Photo = "#NEWPHOTONAME#">

 

Server doesn't like the #ExpandPath ('../images/temp/#photo#')# reference.

 

Error message:  The value of the attribute source, which is currently C:/HOSTINGSPACES/virginia/virginiaequestrian.com/wwwroot/images/temp/IMG_2123.JPG, is invalid.

 

Checking the folder, the file was uploaded to the correct "temp" folder, and is in fact there. Any help appreciated!

    This topic has been closed for replies.

    3 replies

    Charlie Arehart
    Community Expert
    Community Expert
    June 16, 2021

    Chuck, you have misunderstood me. See the first sentence in my first comment: "So if you are on the server, and drop that value...into the address bar of your browser, the image appears?"

     

    You were saying that the value (used as the SOURCE for the rename) DOES exist, though CF said it was "invalid".

     

    My suggestion was a way to prove whether it DOES exist, and then to help perhaps identify where the problem may be. 

    /Charlie (troubleshooter, carehart. org)
    Participating Frequently
    June 21, 2021

    Hi Charlie,

     

    Thank you for your insights and input.  I have worked through many of the issues, and am able to successfully upload an image, copy it to the proper directory.  Now I am running into an issue that seems to be tied to cfexecute.  I am using ImageMagick to resize the images, and this issue seems to be tied to this operation.

    The following is the internal exception message: access denied ("coldfusion.tagext.GenericTagPermission" "cfexecute")
    java.security.AccessControlException: access denied ("coldfusion.tagext.GenericTagPermission" "cfexecute")

     

    Thank you for any input or advice.

     

    Charlie Arehart
    Community Expert
    Community Expert
    June 21, 2021

    Glad you got the other issues sorted.

     

    And as for that error, sadly it's what you get when the person running the CF server has restricted the ability to use that tag, which can be done in the CF Admin via its Security>Sandbox Security page (or in older CF versions, it was called "Resource Security" in CF Standard). Whether you will be able to use it depends on a few things...

     

    Is this a shared host you are on? If so, I doubt they will allow for you to use it, as it's regarded as being potentially dangerous.

     

    If it's an organizational server, perhaps you could persuade the person responsible for the CF Admin.

     

    I will note that the sandbox security feature can either be configured to apply to ALL CF apps, or it can be configured to allow for use of a specific tag like that (which might otherwise be blocked) if it's run from a specific directory that has been given permission (in the CF Admin, sandbox security configuration). 

     

    Again, if you're on a shared host, I doubt they will do it. In an organizational server, they may be persuaded. They may also think "it can't be done" for CF Standard, if that's the license they have, but that limitation was lifted from being Enterprise-only in CF11.

     

    Hope that helps.

    /Charlie (troubleshooter, carehart. org)
    Participating Frequently
    June 16, 2021

    Here is my workflow:

    1.  Upload the file to a temp directory

    2.  Rename the file so that it is unique (I append the file name with date/time)

    3.  Deposit the newly named original into an "original" folder

    4.  Resize the file in the "original" folder into a thumbnail and full sized image (using ImageMagick)

    5.  Deposit the thumb/full sized image into the proper directories

    My understanding is that I need to use ExpandPath to tell ImageMagick where the file actually lives on the server (not a relative URL)

     

    Hopefully conveying this correctly.  Again, any help appreciated.

    Participating Frequently
    June 16, 2021

    And here is the URL to the file that was uploaded:

    http://virginiaequestrian.com.wc05.domainhosting.net/images/temp/IMG_2123.JPG

    Here is the location that is returned with the ExpandPath command:

    C:/HOSTINGSPACES/virginia/virginiaequestrian.com/wwwroot/images/temp/IMG_2123.JPG

    Putting that absolute path in a browser shouldn't work, and in fact does not.

    BKBK
    Community Expert
    Community Expert
    June 17, 2021

    It should work. Especially because the file was successfully uploaded.

     

    In any case, I have two suggestions:

    1.  Verify that the directory structure is correct.
      /wwwroot/
          /workingDir/
          /images/
      where workingDir and images are subdirectories, each one level deep under wwwroot. WorkingDir (my naming)  is the directory that contains the CFM page that runs the file-upload tag. The directory /images/ contains the subdirectories /temp/ and /original/.
    2. Simplify the code. For example, as follows:
      <cfset tempFolder=expandPath ('../images/temp')>
      <cfset originalFolder=expandPath ('../images/original')>
      	
      <cffile action="upload" filefield="Photo" destination="#tempFolder#" accept="image/jpeg,image/jpg,image/pjpeg,image/png" nameconflict="MakeUnique" >
      
      <cfset photoName = file.ServerFile>
      <cfset photoSource = tempFolder & "/" & photoName>
      
      <cfset newPhotoName = 'VE_' & dateformat(now(), 'yyyy_mm_dd_') & timeformat(now(), 'hh_mm_ss_') & photoName>
      <cfset photoDestination = originalFolder & "/" & newPhotoName>
      
      <cffile action="rename" source ="#photoSource#" destination="#photoDestination#">​

     

    Charlie Arehart
    Community Expert
    Community Expert
    June 16, 2021

    So if you are on the server, and drop that value (C:/HOSTINGSPACES/virginia/virginiaequestrian.com/wwwroot/images/temp/IMG_2123.JPG) into the address bar of your browser, the image appears?

     

    If not, it would seem there's something confusing you in thinking "it is there". If it DOES work, then it would be odd indeed that cf can't see it, since cf created it (on the upload).

     

    In that case, you may want to assess what the permissions are for that folder, for the user running cf. If it's a service, does it show running as the user "local system" or something else? 

    /Charlie (troubleshooter, carehart. org)
    Participating Frequently
    June 16, 2021

    My understanding is there are two different paths:

    - one that is a URL, which could be pulled from the browser

    - the other is the actual physical location of the file to be manipulated

     

    On the old/current server,  #ExpandPath ('../images/temp/')# renders

    D:\Docs\VirginiaEquestrian\images\temp\

     

    New server, #ExpandPath ('../images/temp/')# renders

    C:\HOSTINGSPACES\virginia\virginiaequestrian.com\wwwroot\images\temp\

     

    My guess is it could be a file folder permissions issue.  Will check with my sys admin for his insights.