Skip to main content
Participating Frequently
October 21, 2009
Question

Image download using cfhttp in the cycle

  • October 21, 2009
  • 2 replies
  • 1495 views

I'm parcing the page and download all image that i find to my server using:

<cfhttp url="#FullPathToImage#" path="#LocalStorePath#">

Don't know why but successfully download only the first image the all other not. At that there is no error appear. cfhttp.responseHeader variable show  return code 200 for each step of cycle.

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    October 25, 2009

    Your syntax may be ambiguous. I would do something like

    <cfhttp url="#FullPathToWebPage#" path="#directory_of_LocalStorePath#" method="get" file="storedPage.htm">

    and then parse storedPage.htm, or something like

    <cfhttp url="#FullPathToWebPage#" method="get">

    and then parse cfhttp.filecontent

    Inspiring
    October 22, 2009

    It's hard to say without seeing the code, to be honest.

    --

    Adam

    S_martAuthor
    Participating Frequently
    October 26, 2009

    <!--- In the cycle I go over all image name with full path that received from parced document
    Variables:
      - pathToSite - physical path to my site root directory, c://inetpub/mysite/
      - pathToLocalDirectory - physical path to my work directory, c://inetpub/mysite/TEMP/
    --->
    <cfloop condition="...">
        <cfset currentImageFullName = ...>

        <!--- Receive only picture name without path --->
        <cfset currentImageName = GetShortNameFromPath(currentImageFullName)>

        <cftry>
            <cfif Find("http://www.mysite.com",currentImageFullName) or NOT Find("http:",currentImageFullName)>
                <!--- if path to picture refer to the local site then copy picture to the work folder--->

                <!--- receive picture name with folder where it is --->
                <cfset tmpImageName = GetImageNameWithDirectory(currentImageFullName)>
                <cffile action="COPY"  source="#pathToSite##tmpImageName#" destination="#pathToLocalDirectory##currentImageName#">
            <cfelse>

                <!--- If  path to the picture refer to external site then download picture from external site to the work folde--->
                <cfhttp url="#currentImageFullName#" path="#pathToLocalDirectory#" resolveurl="No" timeout="120">
            </cfif>
        <cfcatch>
            <!--- If something go wrong then copy default picture instead of real picture--->
            <cffile action="COPY" source="#pathToSite#Images\noimage.gif" destination="#pathToLocalDirectory##currentImageName#">
        </cfcatch>
        </cftry>
    </cfloop>