Skip to content

Instantly share code, notes, and snippets.

@imjn
Created October 22, 2018 07:44
Show Gist options
  • Save imjn/499984a1cda71e421708b1a0e0bd3957 to your computer and use it in GitHub Desktop.
Save imjn/499984a1cda71e421708b1a0e0bd3957 to your computer and use it in GitHub Desktop.
Sample
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