Last active
April 17, 2019 05:00
-
-
Save jirawatee/dc65210aa0ee329364b5ce6f3d81fca0 to your computer and use it in GitHub Desktop.
Firebase Storage - Upload from stream
This file contains 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 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