and-nd-firebase
and-nd-firebase copied to clipboard
2.02.2 firebase storage put file
Implementing Updated Storage Put File and .getDownloadUrl()
{
Uri uri=data.getData();
final StorageReference picref= mstorageReference.child(uri.getLastPathSegment());
UploadTask uploadTask=picref.putFile(uri);
Task<Uri> task=uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if(!task.isSuccessful())
{
throw task.getException();
}
return picref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if(task.isSuccessful())
{
Uri downloadUri=task.getResult();
mdatabaseReference.push().setValue(new FriendlyMessage(null,mUsername,downloadUri.toString()));
}
}
});
}