I am retrieving the download URL from a song file that is stored in firebase storage.The URL that i am getting is not the same URL that is in the firebase storage.
Here is the wrong link i get: com.google.android.gms.tasks.zzu@75f559a
Here is the correct link: https://firebasestorage.googleapis.com/v0/b/fouronesixsound-51999.appspot.com/o/Uploads%2F1221?alt=media&token=56beacd5-9abd-4a74-b294-69eb111fcb00
Here is a link to a picture of my database setup: https://i.stack.imgur.com/DvYcw.jpg
This is my code:
final String fileName = songUri.getLastPathSegment() + "";
//final String fileName1=songUri.getLastPathSegment()+"";
final StorageReference storageRef = storage.getReference();
storageRef.child("Uploads").child(fileName).putFile(songUri)
.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String url =
storageRef.child("Uploads").child(fileName).getDownloadUrl().toString();
//returns the url of the uploaded file
DatabaseReference reference = database.getReference();
reference.child("Uploads").child(fileName).setValue(url).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
Toast.makeText(Upload.this, "File Uploaded Successfully", Toast.LENGTH_SHORT).show();
else
Toast.makeText(Upload.this, "Upload failed", Toast.LENGTH_SHORT).show();
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Upload.this, "Upload failed",Toast.LENGTH_SHORT).show();
}