开发者

How to get remote file size to increment progress bar?

开发者 https://www.devze.com 2023-02-06 15:44 出处:网络
i need to download large pdf from web and i created a progress bar controller. But, how i set max progress value it i don\'t know the pdf size before downloading?

i need to download large pdf from web and i created a progress bar controller.

How to get remote file size to increment progress bar?

But, how i set max progress value it i don't know the pdf size before downloading?

Is there a way to get file size and use it to increment progress bar?

I'm using

myPDFremoteUrl = "http://www.xasdaxxssxx.pdf";
- (float) getFileSize {
    NSFileManager *man = [[NSFileManager alloc] init];
    NSDictionary *attrs = [man attributesOfItemAtPath: myPDFremoteUrl error: NULL];
    UInt32 result = [attrs fileSize];

    return (float)result;开发者_运维知识库
}

but i don't able to check remote size in this way...

any idea?

Thanks


I would use ASIHTTPRequest for your data retrieval. It has progress monitoring built in.

If you really want to stick with what you've got, you can look at the HTTP header. It has a property called "Content-Length" that will help you out.

Good luck.


ASIHTTPRequest has a downloadProgressDelegate that can handle this for you- its very easy to use.


Solved.

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    dimensione = (float)[response expectedContentLength];

    NSLog(@"content-length: %f bytes", dimensione);
}

I forget didReceiveResponse!

good.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号