我已将存储在firebase存储中的pdf文件的url存储在节点Pdf中的数据库中。我试图从存储在数据库中的url的帮助下从firebase存储中下载文件。如何使用存储在firebase数据库中的url下载文件?
public class DownloadFile extends AppCompatActivity{
DatabaseReference databaseReference= FirebaseDatabase.getInstance().getReference();
String root_child="my book";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
databaseReference.child("Pdf").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.hasChild(root_child))
{
String url=dataSnapshot.child(root_child).getValue().toString();
StorageReference island=storageRef.child("books").child(root_child).child(url);
island.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
pdfView.fromFile(file).load();
}
});
}
}
的问题是没有真正体现出了pdf
视图中。当我调试应用程序时,我发现StorageReference island=storageRef.child("books").child(root_child).child(url);
未创建正确的参考。简而言之,该文件不会下载。由于文件名称因用户上传而不同,因此我无法指定文件名,因此我使用'child(url)'
,以便它可以使用url
搜索文件,但我不确定是否正确搜索文件file.Any帮助表示赞赏。
请发布正确的代码以方便阅读。 –
您是否参考https://firebase.google.com/docs/storage/android/download-files – Vij