Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Working with files in coldfusion

Posted on 2012-03-28
5
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 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