firebase_download_example icon indicating copy to clipboard operation
firebase_download_example copied to clipboard

Files not downloading

Open altmash5 opened this issue 3 years ago • 3 comments

when i click the download button it shows file downloaded but the file don't get downloaded and doesn't get save anywhere

altmash5 avatar Oct 26 '21 10:10 altmash5

@altmash5 I guess there is some issue in the downloadFile() Anyway I just changed it a little bit as I want my application to make its own directory in external storage if not created or just save the file in it if its already created so I did the following:

static Future downloadFile(Reference ref) async { Directory directory = await getExternalStorageDirectory(); String newPath = ""; print(directory); List<String> paths = directory.path.split("/"); for (int x = 1; x < paths.length; x++) { String folder = paths[x]; if (folder != "Android") { newPath += "/" + folder; } else { break; } } newPath = newPath + "/put in the name of directory you want to store the file in"; directory = Directory(newPath); File saveFile = File('${directory.path}/${ref.name}'); if (!await directory.exists()) { await directory.create(recursive: true); } if (await directory.exists()) { await ref.writeToFile(saveFile); } }

Thats it, Hope it helps.

Abhijit-007a avatar Oct 29 '21 14:10 Abhijit-007a

@altmash5 I guess there is some issue in the downloadFile() Anyway I just changed it a little bit as I want my application to make its own directory in external storage if not created or just save the file in it if its already created so I did the following:

static Future downloadFile(Reference ref) async { Directory directory = await getExternalStorageDirectory(); String newPath = ""; print(directory); List paths = directory.path.split("/"); for (int x = 1; x < paths.length; x++) { String folder = paths[x]; if (folder != "Android") { newPath += "/" + folder; } else { break; } } newPath = newPath + "/put in the name of directory you want to store the file in"; directory = Directory(newPath); File saveFile = File('${directory.path}/${ref.name}'); if (!await directory.exists()) { await directory.create(recursive: true); } if (await directory.exists()) { await ref.writeToFile(saveFile); } }

Thats it, Hope it helps.

Hello there; Can you post the exact code screen? I couldn't add the code you wrote. Thanks.

ayzek67 avatar Oct 29 '21 19:10 ayzek67

image For the black wipe out area write in the name of directory you want to store the file in Here it is Hope it helps

Abhijit-007a avatar Oct 30 '21 21:10 Abhijit-007a