我正在从存储在Firebase存储器中的歌曲文件中检索下载URL。即使我使用的是addOncompletelistener
,我得到的URL也与Firebase存储中的URL不同。
这是我得到的错误链接:com.google.android.gms.tasks.zzu@75f559a
这是我的数据库设置图片的链接:https://imgur.com/a/Gtl1ThZ
这是我的代码:
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) {
storageRef.child("Uploads").child(fileName).getDownloadUrl()
.addOnCompleteListener(new OnCompleteListener < Uri > () {
@Override
public void onComplete(@NonNull Task < Uri > task) {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
reference.child("Uploads").child(fileName).setValue(downloadUri.toString()).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();
}
});
} else {
Toast.makeText(Upload.this, "upload failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Upload.this, "Upload failed", Toast.LENGTH_SHORT).show();
}