我需要这个:
我可以将视频文件成功上传到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);
}
});
}
});
}
})
尝试一下
task.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String fileUrl = uri.toString()
}
});