Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun uploadProfilePicture(profilePicture: Bitmap, callback: (Exception?, Uri?) -> Unit) {
- Log.v("STORAGE", "Uploading a profile picture")
- val baos = ByteArrayOutputStream()
- val storage = FirebaseStorage.getInstance()
- val filePath = "profilePictures/${auth.currentUser!!.uid}"
- val storageRef = storage
- .reference
- .child(filePath)
- profilePicture.compress(Bitmap.CompressFormat.JPEG, 100, baos)
- val img = baos.toByteArray()
- storageRef.putBytes(img).let {
- it.continueWithTask { task ->
- if (!task.isSuccessful) {
- task.exception?.let { e ->
- callback(e, null)
- }
- }
- storageRef.downloadUrl
- }.addOnCompleteListener{ task ->
- if (task.isSuccessful) {
- Log.v("STORAGE", "Profile picture upload successful")
- callback(null, task.result)
- } else {
- Log.e("STORAGE", "Profile picture upload failed")
- callback(task.exception, null)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement