我在从Firebase存储android检索视频时遇到问题。 getDownloadurl对我不起作用

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

我需要这个enter image description here

Task uriTask = uploadTask.continueWithTask(new Continuation>(){@Override然后,公共任务(@NonNull任务任务)将引发异常{if(!task.isSuccessful())抛出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
1个回答
0
投票
task.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            String fileUrl = uri.toString()
        }
    });

添加成功侦听器以下载URL。如果您想获取网址,则必须这样做


0
投票

尝试一下

private Uri uri;    //global variable

当用户从电话中选择视频时,[内部onActivityResult()设置uri]

onActivityResult(int requestCode, int resultCode, Intent data)
uri = data.getData(); 

最终获得下载URL

final StorageReference ref = storageReference.child("firebaseFilePath");

    ref.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                @Override
                public void onSuccess(Uri uri) {
                    //now sUrl contains downloadURL
                    sUrl = uri.toString();

                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    }
            });


        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.