0

When I retrieve an image from storage, it takes about 1-2 seconds. If I could save that image locally, I wouldn't have to wait. Is there any solutions to this?

  • yes you can save image locally in document directory, once image is downloaded save that path without "document directory path". document directory path changes every time you run your app, so you have to give that path dynamically. Hope this help. – Ratnesh Shukla Feb 18 '17 at 06:45
  • @RatneshShukla thanks! but could I know where I could find this "document directory path"? or could you give me an example code? I am new to coding so please understand. – Dong Hae JANG Feb 18 '17 at 17:16
  • let fileManager = NSFileManager.defaultManager() let paths = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString).stringByAppendingPathComponent("apple.jpg") – Ratnesh Shukla Feb 18 '17 at 17:28
  • let image = UIImage(named: "apple.jpg") let imageData = UIImageJPEGRepresentation(image!, 0.5) fileManager.createFileAtPath(paths as String, contents: imageData, attributes: nil) – Ratnesh Shukla Feb 18 '17 at 17:29
  • @RatneshShukla thanks! is would UIImageJPEGRepresentation(image!, 0.5) the maximum compression that jpeg can represent? – Dong Hae JANG Feb 23 '17 at 01:50
  • @DongHaeJANG what is your solution ? – nikdange_me Mar 09 '17 at 14:30

1 Answers1

1

I think you should use SDWebImage library to download (JPEG, PNG, ...) images from firebase storage. You need to pass the 'URL' of the image, you wish to download.

It is asynchronous image downloader with memory + disk image caching with automatic cache expiration handling and guarantee that the same URL won't be downloaded several times and much more. Please go through, it's really nice!

Here the links, https://github.com/rs/SDWebImage.

nikdange_me
  • 2,949
  • 2
  • 16
  • 24