This question already has an answer here:
I tried finding on a lot of stackoverflow questions, and many other places, but could not find a working method.
I am uploading a picture to firebase storage, and on upload I want a download link for that picture/document.
taskSnapshot.getDownloadUrl()
is now deprecated,
so they have mentioned to use getDownloadUrl
on the Firebase Storage Reference, or getResult
on the taskSnapshot
, but both return some jargon and I am not able to get a proper download url.
btnUploadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!ImageUri.toString().trim().equals(""))
{
final StorageReference imageRef = mFirebaseStorage.child("some.jpg");
imageRef.putFile(ImageUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_SHORT).show();
Log.d("UploadSuccess", ""+task.getResult()+"\n"+mFirebaseStorage.getDownloadUrl());
}
});
}else
{
Toast.makeText(MainActivity.this, "Please Select An Image.", Toast.LENGTH_SHORT).show();
}
}
});
this gave me an log Output :
D/UploadSuccess: com.google.firebase.storage.UploadTask$TaskSnapshot@fff6f13 com.google.android.gms.tasks.zzu@c781349
and the version of firebase/storage i am using :
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.google.firebase:firebase-storage:16.1.0'
Try this