-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate file download failed same file name #900
Comments
@Hackerdash can you post some logs ? |
@Hackerdash can you use the latest version and see if your issue is fixed? otherwise will close the issue since i cannot reproduce |
I have encountered the problem of not downloading a file with the same name, if one has already been downloaded before. Future<String> getFilenamePath(
Directory directory, String originalFileName) async {
String fileName = originalFileName;
var i = 0;
while (true) {
String fullPath = directory.path + Platform.pathSeparator + fileName;
if (await File(fullPath).exists()) {
i++;
List splits = originalFileName.split('.');
fileName = ["${splits[0]}.$i", splits[1]].join('.');
} else {
break;
}
}
return fileName;
}
Future<void> startDownload(String url, String cookies) async {
final uri = Uri.parse(url);
Directory directory = await getApplicationDocumentsDirectory();
if (Platform.isAndroid) {
// In this direcory we search already download file.
directory = Directory('/storage/emulated/0/Download');
}
String filename = uri.pathSegments.last;
final fileName = await getFilenamePath(directory, filename);
await FlutterDownloader.enqueue(
url: url,
fileName: fileName,
savedDir: directory.path,
showNotification: true,
openFileFromNotification: true,
// saveInPublicStorage: false here we set up custom path to Download,
// need for get unique name of file,
// else download was falid.
saveInPublicStorage: false,
);
} I'll be only too happy to get rid of this ugly code, but it works. If there is a more successful implementation, I will be glad to consider it |
@ggmanuilov
|
Describe the bug
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Screenshots
Device information:
The text was updated successfully, but these errors were encountered: