Imaginary icon indicating copy to clipboard operation
Imaginary copied to clipboard

Can I download big image without crash

Open smolskyaleksey opened this issue 7 years ago • 5 comments

If I download big image via

self.session.dataTask(with: request, completionHandler: { [weak self] data, response, error}

image stored inside response. And I can catch crash. How can I use URLSession's method

func downloadTask(with request: URLRequest, 
completionHandler: @escaping (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask

to store image in file

smolskyaleksey avatar Feb 06 '19 16:02 smolskyaleksey

Why do you close issue without any answer?

smolskyaleksey avatar Jun 07 '20 06:06 smolskyaleksey

Hello @smolskyaleksey,

Sorry for not writing before. I haven't been able to reproduce this issue. Could you help me with additional steps to reproduce? How big was the file you were trying to download? Is this still an issue for you?

3lvis avatar Jun 07 '20 11:06 3lvis

Yes, try to download big image above 100 mgb. dataTask represent image in memory in data parameter. U can crash because you don't have enough memory.

smolskyaleksey avatar Jun 08 '20 10:06 smolskyaleksey

OK! Will try to reproduce, this might be caused because of limitations in URLSession so it might require us to implement background downloads in order to make this work. WIll investigate further.

3lvis avatar Jun 08 '20 22:06 3lvis

OK! Will try to reproduce, this might be caused because of limitations in URLSession so it might require us to implement background downloads in order to make this work. WIll investigate further.

You can use

func downloadTask(with request: URLRequest, 
completionHandler: @escaping (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask

It downloads file directly in file system

smolskyaleksey avatar Jun 08 '20 22:06 smolskyaleksey