Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Image incomplete download #90

Closed
HamzaGhazouani opened this issue Jan 12, 2016 · 4 comments
Closed

Image incomplete download #90

HamzaGhazouani opened this issue Jan 12, 2016 · 4 comments

Comments

@HamzaGhazouani
Copy link
Contributor

Firstly, thank you for this nice library.

I have a problem with only some specifics URLs :
When I have a bad network conditions, I get incomplete download, and the image is not stored in cache :

capture d ecran 2016-01-12 a 15 18 48

The header of the URL of the image :

Cache-Control → private
Connection → keep-alive
Content-Length → 94896
Content-Type → image/jpg
Date → Tue, 12 Jan 2016 14:21:14 GMT
Expires → Thu, 11-Feb-2016 14:21:13 GMT
Pragma → cache
Server → Rocket 1.2.6 Python/2.7.3
X-Powered-By → web2py

Example of URL : http://preprod.verybuzzy.com:8000/bitc/Webservice_Media/getUserPhoto/1/58/1

Have you any idea what it is this bug?
Thank you

@kean
Copy link
Owner

kean commented Jan 12, 2016

Hi! My theory is that it happens when NSURLSessionTask fails with some error, but already has some loaded data. I haven't worked with this code for a while, but it seems that the reason for this is here in DFImageManagerLoader class:

- (void)_loadOperation:(nonnull _DFImageLoadOperation *)operation didCompleteWithData:(nullable NSData *)data info:(nullable NSDictionary *)info error:(nullable NSError *)error {
    if (data.length) {
        typeof(self) __weak weakSelf = self;
        [_decodingQueue addOperationWithBlock:^{
            UIImage *image = [weakSelf.conf.decoder imageWithData:data partial:NO];
            [weakSelf _loadOperation:operation didCompleteWithImage:image info:info error:error];
        }];
    } else {
        [self _loadOperation:operation didCompleteWithImage:nil info:info error:error];
    }
}

We've experienced this kind of behaviour a while ago, but we haven't paid that much attention to it. It might be a good time to actually fix this. Thanks for the report.

@kean
Copy link
Owner

kean commented Jan 12, 2016

This should not be happening when you use AFNetworking subspec, because AFURLSessionManager prevents completion handler from being called with response data when error occurred.

@HamzaGhazouani
Copy link
Contributor Author

I fixed that by changing the method _loadOperation as you pointed out below
Indeed the image size is smaller than the real size

- (void)_loadOperation:(nonnull _DFImageLoadOperation *)operation didCompleteWithData:(nullable NSData *)data info:(nullable NSDictionary *)info error:(nullable NSError *)error {
    if (error || !data.length) {
        [self _loadOperation:operation didCompleteWithImage:nil info:info error:error];
    }
    else {
        typeof(self) __weak weakSelf = self;
        [_decodingQueue addOperationWithBlock:^{
            UIImage *image = [weakSelf.conf.decoder imageWithData:data partial:NO];
            [weakSelf _loadOperation:operation didCompleteWithImage:image info:info error:error];
        }];
    }
}

Thank you a lot

@kean
Copy link
Owner

kean commented Jan 12, 2016

A pull request would be nice 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants