Created
October 22, 2018 07:45
-
-
Save imjn/ff5c49e52c932e1b1c4cd941598789c0 to your computer and use it in GitHub Desktop.
Sample
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