Skip to content

Instantly share code, notes, and snippets.

@e-lin
Created June 25, 2019 10:13
Show Gist options
  • Save e-lin/9477597b184a961cb88f6814f2472580 to your computer and use it in GitHub Desktop.
Save e-lin/9477597b184a961cb88f6814f2472580 to your computer and use it in GitHub Desktop.
Uploading to Firebase Cloud Storage
private fun uploadFile(f: File) {
val sdf = SimpleDateFormat("yyyyMMddHHmmss", Locale.US)
val storagePath = "/pictures/${sdf.format(Date())}.jpg"
val ref = FirebaseStorage.getInstance().getReference(storagePath)
ref.putFile(Uri.fromFile(f))
.addOnSuccessListener(this) {
Log.i(TAG, "picture uploaded")
}
.addOnFailureListener(this) { e ->
Log.i(TAG, "upload failed", e)
}
.addCompleteListener(this) {
f.delete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment