Skip to content

Instantly share code, notes, and snippets.

@imjn
Created October 22, 2018 07:43
Show Gist options
  • Save imjn/2f3039e0cbe4dc69a60c28af0dd68140 to your computer and use it in GitHub Desktop.
Save imjn/2f3039e0cbe4dc69a60c28af0dd68140 to your computer and use it in GitHub Desktop.
StorageService.swift
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