Skip to content

Instantly share code, notes, and snippets.

func downloadImage(from storageImagePath: String) {
// 1. Get a filePath to save the image at
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let filePath = "file:\(documentsDirectory)/myimage.jpg"
// 2. Get the url of that file path
guard let fileURL = URL(string: filePath) else { return }
// 3. Start download of image and write it to the file url
storageDownloadTask = storageRef.child(storageImagePath).write(toFile: fileURL, completion: { (url, error) in