Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private fun uploadImage(){
if(filePath != null){
val ref = storageReference?.child("uploads/" + UUID.randomUUID().toString())
val uploadTask = ref?.putFile(filePath!!)
val urlTask = uploadTask?.continueWithTask(Continuation<UploadTask.TaskSnapshot, Task<Uri>> { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
}
}
return@Continuation ref.downloadUrl
})?.addOnCompleteListener { task ->
if (task.isSuccessful) {
val downloadUri = task.result
addUploadRecordToDb(downloadUri.toString())
} else {
// Handle failures
}
}?.addOnFailureListener{
}
}else{
Toast.makeText(this, "Please Upload an Image", Toast.LENGTH_SHORT).show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.