6 Replies - 3048 Views - Last Post: 10 February 2011 - 09:38 AM Rate Topic: -----

#1 SleepingInChapel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 59
  • Joined: 02-January 09

Getting Remote File Size Before Downloading

Posted 09 February 2011 - 03:07 PM

Hi,

I'm downloading an xml file to my server using <cfhttp>. Is there a method to get the total size of the xml file before I download it?

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Getting Remote File Size Before Downloading

#2 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Getting Remote File Size Before Downloading

Posted 10 February 2011 - 07:05 AM

Try doing a cfdump of the cfhttp variable. In either the response or the responseHeader there will probably be a size in there. You will need a regular expression to pull it out. If you aren't familiar with regex then post the response or responseHeader and I will take a look at it.
Was This Post Helpful? 1
  • +
  • -

#3 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1938
  • View blog
  • Posts: 3,480
  • Joined: 13-January 08

Re: Getting Remote File Size Before Downloading

Posted 10 February 2011 - 07:14 AM

How are you downloading a file with CFHTTP? I don't do a lot of downloads but when I have I've used CFFILE or CFFTP to get remote files. Naturally, with both of those you can get file sizes before you move files.

Can you post up the portion of your code where you're using CFHTTP? I'd be curious to see how you're doing this.
Was This Post Helpful? 0
  • +
  • -

#4 SleepingInChapel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 59
  • Joined: 02-January 09

Re: Getting Remote File Size Before Downloading

Posted 10 February 2011 - 08:20 AM

View PostCraig328, on 10 February 2011 - 08:14 AM, said:

How are you downloading a file with CFHTTP? I don't do a lot of downloads but when I have I've used CFFILE or CFFTP to get remote files. Naturally, with both of those you can get file sizes before you move files.

Can you post up the portion of your code where you're using CFHTTP? I'd be curious to see how you're doing this.


I know it's probably not the best code ever, but here's the gist of what I'm doing...

<cftry>
    <cfhttp url="#xmlUrl#" charset="utf-8">
    <cfcatch type="any">
        Oops, there is a problem with the news feed http, please check back soon.
        <cfabort>
    </cfcatch>
</cftry>

<cffile charset="utf-8" action="write" file = "#strPath##strFilename#" output = "#cfhttp.filecontent#">



HeartOnFire, thanks for the suggestion. I'll try it. I don't know why I hadn't thought to do that before...
Was This Post Helpful? 0
  • +
  • -

#5 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1938
  • View blog
  • Posts: 3,480
  • Joined: 13-January 08

Re: Getting Remote File Size Before Downloading

Posted 10 February 2011 - 08:27 AM

Ah! Okay. I see what you're doing. You're kinda consuming a web service sort of.

In any event, your original question "Is there a method to get the total size of the xml file before I download it" = not really. You'll have to make the CFHTTP call and get the file before you can do the CFDUMP of the variable and that CFDUMP won't be available until the CFHTTP call is complete.

You could ask the hosting source for that XML file if they have a summary file available that might contain the filename and size that you could reference. If they don't they may consider creating one if you can give them a good reason to. :)
Was This Post Helpful? 1
  • +
  • -

#6 SleepingInChapel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 59
  • Joined: 02-January 09

Re: Getting Remote File Size Before Downloading

Posted 10 February 2011 - 08:43 AM

View Postxheartonfire43x, on 10 February 2011 - 08:05 AM, said:

Try doing a cfdump of the cfhttp variable. In either the response or the responseHeader there will probably be a size in there. You will need a regular expression to pull it out. If you aren't familiar with regex then post the response or responseHeader and I will take a look at it.


Hmm... it doesn't look like there's much information in the response header. Here's what I'm getting:

Posted Image

I'll be downloading other things as well, like videos and images for the news feed. I'll use the remote file size information to create a progress bar with jQuery, then I'll probably have ColdFusion poll the file size of the local file until to update the progress bar.

Not an extremely important feature, but it would be nice to let the user know what's going on.

Craig--yeah that might be worth looking into. I'll probably just ask our provider if they can provide a summary. Thanks!
Was This Post Helpful? 0
  • +
  • -

#7 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Getting Remote File Size Before Downloading

Posted 10 February 2011 - 09:38 AM

Craig is correct. You won't be able to get anything before downloading. You may want to look into the Java stuff happening underneath ColdFusion. There may be a method there to get the header without getting the file. Not quite sure if that is possible or not.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1