I have successfully uploaded the image to Storage, but I have a problem that when my image is large in size it will be slow in rendering to the UI. I want to resize my images to the same default size before uploading to Storage.
func uploadImageToStorage(image: UIImage) {
if let imageData = image.jpegData(compressionQuality: 1) {
let storage = Storage.storage()
let storageRef = storage.reference()
let testRef = storageRef.child("avatar/\(user.id)/avatar.png")
testRef.putData(imageData, metadata: nil) {( _, error) in
if let error = error {
print("an error has occured - \(error.localizedDescription)")
} else {
print("image uploaded successfully")
}
}
} else {
print("Coldn't unwrap/case imgae to data")
}
}