Created
October 22, 2018 07:43
-
-
Save imjn/2f3039e0cbe4dc69a60c28af0dd68140 to your computer and use it in GitHub Desktop.
StorageService.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
import FirebaseStorage | |
struct StorageService { | |
// provide method for uploading images | |
static func uploadImage(_ image: UIImage, at reference: StorageReference, completion: @escaping (URL?) -> Void) { | |
guard let imageData = UIImageJPEGRepresentation(image, 0.5) else { | |
return completion(nil) | |
} | |
reference.putData(imageData, metadata: nil, completion: { (metadata, error) in | |
if let error = error { | |
assertionFailure(error.localizedDescription) | |
return completion(nil) | |
} | |
completion(metadata?.downloadURL()) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment