我已將存儲在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