Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active April 17, 2019 05:01
Show Gist options
  • Select an option

  • Save jirawatee/158fc36a00c75632038bf2c7fbc3eb01 to your computer and use it in GitHub Desktop.

Select an option

Save jirawatee/158fc36a00c75632038bf2c7fbc3eb01 to your computer and use it in GitHub Desktop.
Firebase Storage - Upload from local file
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