Last active
April 17, 2019 05:01
-
-
Save jirawatee/158fc36a00c75632038bf2c7fbc3eb01 to your computer and use it in GitHub Desktop.
Firebase Storage - Upload from local file
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 void uploadFromFile(String path) { | |
| Helper.showDialog(this); | |
| Uri file = Uri.fromFile(new File(path)); | |
| StorageReference imageRef = folderRef.child(file.getLastPathSegment()); | |
| mUploadTask = imageRef.putFile(file); | |
| mUploadTask.addOnFailureListener(new OnFailureListener() { | |
| @Override | |
| public void onFailure(@NonNull Exception exception) { | |
| Helper.dismissDialog(); | |
| mTextView.setText(String.format("Failure: %s", exception.getMessage())); | |
| } | |
| }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { | |
| @Override | |
| public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { | |
| Helper.dismissDialog(); | |
| imageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() { | |
| @Override | |
| public void onSuccess(Uri uri) { | |
| mTextView.setText(uri.toString()); | |
| } | |
| }); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment