2

Looking for a way to retrieve a file size from a web server using cocoa/foundation. I know one can use NSURLconnection which will return NSURLResponse that contains the file size. Is there any other way to get the size. I'm looking for a synchronous way of doing it so when i do [myClass getsize] the size is returned.

Thanks

MikeM
  • 59
  • 1
  • 7
  • 2
    Note that doing it synchronously will make your app unusable until the response comes back, which could be X minutes from now or never at all. – Peter Hosey May 01 '10 at 23:18

1 Answers1

4

You can use a NSMutableURLRequest to send a HTTP HEAD request (there’s a method called setHTTPMethod). You’ll get the same response headers as with GET, but you won’t have to download the whole resource body. And if you want to get the data synchronously, use the sendSynchronousRequest… method of NSURLConnection.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • @zoul: Indeed that works. Thanks for your help. Here is what i did: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]; [request setHTTPMethod:@"HEAD"]; – MikeM Apr 30 '10 at 15:48