Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active April 17, 2019 05:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirawatee/dc65210aa0ee329364b5ce6f3d81fca0 to your computer and use it in GitHub Desktop.
Save jirawatee/dc65210aa0ee329364b5ce6f3d81fca0 to your computer and use it in GitHub Desktop.
Firebase Storage - Upload from stream
private void uploadFromStream(String path) {
Helper.showDialog(this);
InputStream stream = null;
try {
stream = new FileInputStream(new File(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mUploadTask = imageRef.putStream(stream);
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