• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: getting a nsurl file size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting a nsurl file size


  • Subject: Re: getting a nsurl file size
  • From: Eric Smith <email@hidden>
  • Date: Sun, 29 Jan 2012 08:13:19 -0800

Charles,

Works like a charm.  Thank you!

Eric


On Jan 28, 2012, at 11:28 PM, Charles Srstka wrote:

> On Jan 29, 2012, at 12:21 AM, Ken Thomases wrote:
>
>> * The keys that are valid for that method are those listed in the NSURL documentation.  They may bear no relation to HTTP response header fields.  So, I see no reason to believe that "content-length" is a valid key.  Have you tried NSURLFileSizeKey?
>>
>>
>>> If I send:
>>>
>>> value = [path propertyForKey:@"content-length"];
>>>
>>> which is deprecated, I get the correct file size.
>>
>> That may be fluke.
>
> NSURL’s now deprecated -propertyForKey: method existed long before any of those NSURL*Key constants did, so it’s difficult to imagine what could have been passed to it other than HTTP response header field names.
>
> At any rate, this should do what you want:
>
> NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
>
> req.HTTPMethod = @"HEAD";
> [req setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
>
> void (^completionBlock)(NSURLResponse *resp, NSData *data, NSError *error) = ^(NSURLResponse *resp, NSData *data, NSError *error) {
>     if([resp isKindOfClass:[NSHTTPURLResponse class]]) {
>         NSLog(@"length is %@", [((NSHTTPURLResponse *)resp).allHeaderFields objectForKey:@"Content-Length"]);
>     }
> };
>
> [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:completionBlock];
>
> Charles

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >getting a nsurl file size (From: Eric Smith <email@hidden>)
 >Re: getting a nsurl file size (From: Ken Thomases <email@hidden>)
 >Re: getting a nsurl file size (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: getting a nsurl file size
  • Next by Date: Re: Use of Application nib file template
  • Previous by thread: Re: getting a nsurl file size
  • Next by thread: Re: getting a nsurl file size
  • Index(es):
    • Date
    • Thread