无法检索正确的下载URL

时间:2019-04-04 20:14:06

标签: android firebase firebase-storage

我正在从存储在Firebase存储器中的歌曲文件中检索下载URL。即使我使用的是addOncompletelistener,我得到的URL也与Firebase存储中的URL不同。

这是我得到的错误链接:com.google.android.gms.tasks.zzu@75f559a

这是正确的链接:https://firebasestorage.googleapis.com/v0/b/fouronesixsound-51999.appspot.com/o/Uploads%2F1221?alt=media&token=56beacd5-9abd-4a74-b294-69eb111fcb00

这是我的数据库设置图片的链接: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();
  }

0 个答案:

没有答案