Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Working with files in coldfusion

Posted on 2012-03-28
5
Medium Priority
?
225 Views
Last Modified: 2012-03-28
I get a daily txt file with image links (see attached txt file)textfile.txt
And I parse these links into a MySQL 5 database table.
What I want to do is download these images to a folder on my server, and rename them to match the MLS Number, like 117220-1.jpg, 117220-2.jpg, 117220-3.jpg, etc..

In looking at adobe.com I found the following bit of code that should download the image to my folder but what I need help with is when there are more than one photo per MLS Number as described above. Am I even on the right track? Any help appreciated!

<!---query my table and loop over results--->
<cfquery name="photos">
select * from listings.photos where Date Last Modified IS #Now()#
</cfquery>

<cfoutput query="photos">

<cfhttp
    method="Get"
    url="#Photo Link#"
    path="c:\myimagesfolder"
    file="#MLS Number#.jpg">
<cfoutput>
    #cfhttp.MimeType#
</cfoutput>

</cfoutput>
0
Comment
Question by:Bang-O-Matic
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 37779164
If it's not a lot of images (because cfhttp would timeout), you could use a grouped cfoutput with a counter variable.  The counter would act as a suffix for the image names.  Just increment it on each loop and reset it each time the MLS number changes.  That'll give you names like: 52188_1.jpg, 52188_2.jpg, etc...
               
* note: must order by MLS number or it won't work
* use a broader date filter than IS NOW()

<cfquery name="photos">
    SELECT  PhotoLink, MLSNumber FROM  listings.photos
    WHERE  DateLastModified > #theLastDateYouPulledImages#
    ORDER BY MLSNumber
</cfquery>

<cfoutput query="photos" group="MLSNumber">
        <!--- this is a new MLS number. reset the counter --->
        <cfset counter = 1>
        <cfoutput>
            <cfhttp method="Get" url="#PhotoLink#"
                        path="c:\myimagesfolder"
                        file="#MLSNumber#_#counter#.jpg">
             
              ... do other stuff
        </cfoutput>
</cfoutput>
0
 

Author Comment

by:Bang-O-Matic
ID: 37779227
Hi _agx_, thanks for this solution! Initially I will have to download all images, approx 80,000. Then I can just run this update daily. How should I approach getting all the images the first time?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37779289
I doubt you'll be able to get all 80K in one shot.  The page will almost certainly timeout 1st, assuming the other site doesn't throttle access and block that kind of volume.

I'd probably set it up as a one time scheduled task. The task would process the images in batches of N (some reasonable number like 100 or 250). The basic process is:

- create a cfm script that queries your image table for the next N unprocessed images.
- loop through the results and for each one:
      1) download the image
      2) mark the record as processed
      lather, rinse, repeat until there are no more images

- Finally query the table to get the total unprocessed images remaining. If it's > 0, have the scheduled task run itself again. When there are no more images to process the task ends.

Though if you want to use the "grouped" output above, you'd also have to keep track of the last MLS number and counter from the previous run. Otherwise you might overwrite a few images. But you can easily pass them along along as URL parameters.
0
 

Author Comment

by:Bang-O-Matic
ID: 37779315
Sounds like a plan. Thanks for your help!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37779420
WHERE  DateLastModified > #theLastDateYouPulledImages#

Typo correction that obviously should be on or before theLastDateYouPulledImages. ;-)

.. and I left out the increment in the pseudo code. But that's pretty self explanatory.

<cfoutput query="photos" group="MLSNumber">
        <!--- this is a new MLS number. reset the counter --->
        <cfset counter = 1>
        <cfoutput>
            <cfhttp method="Get" url="#PhotoLink#"
                        path="c:\myimagesfolder"
                        file="#MLSNumber#_#counter#.jpg">
             
              ... do other stuff
            <cfset counter = counter + 1>
        </cfoutput>
</cfoutput>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question