我需要这个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);
}
});
}
});
}
})
task.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String fileUrl = uri.toString()
}
});
添加成功侦听器以下载URL。如果您想获取网址,则必须这样做
尝试一下
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) {
}
});
}
});