Created
June 25, 2019 10:13
-
-
Save e-lin/9477597b184a961cb88f6814f2472580 to your computer and use it in GitHub Desktop.
Uploading to Firebase Cloud Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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