在上传到Android中的Firebase Cloud Storage后,我无法获取视频下载网址。 getDownloadUrl无法正常工作[重复]

问题描述 投票:0回答:2

我需要这个:“在此处输入图像描述”

我可以将视频文件成功上传到Firebase Storage,但没有下载网址。这是我的上传代码:

 Task<Uri> uriTask = 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();
                downloadurl = mStorageRef.getDownloadUrl().toString();
                return mStorageRef.child(name1).getDownloadUrl();
            }
     }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {

                if(task.isSuccessful())
                   downloadurl = task.getResult().toString();

                   Map<String,Object> user = new HashMap<>();
                   user.put("videoname",name1);
                   user.put("videolink",downloadurl);
                   firebaseFirestore.collection("videos").document(userID).collection("video").document().set(user).addOnSuccessListener(new OnSuccessListener<Void>() {
                     @Override
                     public void onSuccess(Void aVoid) {
                          Toast.makeText(getActivity(),"Uploaded Successfully",Toast.LENGTH_SHORT).show();
                          progressBar.setVisibility(View.GONE);
                      }
                    });
                   }
                 });
               }
             })
android firebase firebase-storage
2个回答
1
投票

尝试一下


0
投票
task.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            String fileUrl = uri.toString()
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.