Path is not taking as given and downloading in Download folder only
See original GitHub issueI am getting issues while downloading videos from the server. I had given the path for Android as (/storage/emulated/0/Movies/MyApp
) but It’s downloading video in the “Download” folder only.
Here is my code:
requestDownloadFile(String link, bool isShare) async {
_permissionReady = await _checkPermission();
if (_permissionReady) {
FlutterDownloader.registerCallback(callback);
var _directory = Platform.isAndroid ? Directory('/storage/emulated/0/Movies/MyApp') : await getApplicationDocumentsDirectory();
String newPath = _directory.absolute.path;
print("Absolute Path: $newPath");
if(Platform.isIOS) {
newPath += '/MyApp';
}
_directory = Directory(newPath);
bool hasExisted = await _directory.exists();
if (!hasExisted) {
_directory.create();
}
_localPath = _directory.path;
print(_localPath);
String fileName = link.split('/').last;
print(fileName);
print(_localPath + '/' + fileName);
String localFilePath = _localPath + '/' + fileName;
if (await File(localFilePath).exists() && isShare) {
Share.shareFiles([localFilePath]);
} else {
ReceivePort _port = ReceivePort();
IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
streamSubscription = _port.listen((dynamic data) {
DownloadTaskStatus status = data[1];
if (status.value == 3) {
print(fileName);
print('Downloaded Path: ${_localPath + ' / ' + fileName}');
streamSubscription.cancel();
IsolateNameServer.removePortNameMapping('downloader_send_port');
// Share only if clicked on share otherwise download
if (isShare) Share.shareFiles([_localPath + '/' + fileName]);
}
});
print('Path Before Downloading: $_localPath');
await FlutterDownloader.enqueue(url: link, savedDir: _localPath, showNotification: true, openFileFromNotification: true, fileName: fileName);
}
}
}
Here are the logs:
I/flutter (25574): Absolute Path: /storage/emulated/0/Movies/MyApp
I/flutter (25574): Directory: '/storage/emulated/0/Movies/MyApp'
I/flutter (25574): /storage/emulated/0/Movies/MyApp
I/flutter (25574): gbUG2Ag6LHA4UGoyG2agOeV6Uu03Thn8RVcsTu1Q.mp4
I/flutter (25574): /storage/emulated/0/Movies/MyApp/gbUG2Ag6LHA4UGoyG2agOeV6Uu03Thn8RVcsTu1Q.mp4
I/flutter (25574): Path Before Downloading: /storage/emulated/0/Movies/MyApp
D/DownloadWorker(25574): DownloadWorker{url=https://example.com/gbUG2Ag6LHA4UGoyG2agOeV6Uu03Thn8RVcsTu1Q.mp4,filename=gbUG2Ag6LHA4UGoyG2agOeV6Uu03Thn8RVcsTu1Q.mp4,savedDir=/storage/emulated/0/Movies/MyApp,header=,isResume=false
But after downloading its printing (from the library) as below:
D/DownloadWorker(25574): File downloaded (/storage/emulated/0/Download/gbUG2Ag6LHA4UGoyG2agOeV6Uu03Thn8RVcsTu1Q.mp4)
D/DownloadWorker(25574): Setting an intent to open the file /storage/emulated/0/Download/gbUG2Ag6LHA4UGoyG2agOeV6Uu03Thn8RVcsTu1Q.mp4
Can you please tell me why it’s downloading the video in the Download folder only? Why it’s not taking the path I have given?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:17 (1 by maintainers)
Top Results From Across the Web
General Path To Downloads Folder - java - Stack Overflow
I have a DownloadTask class in java that takes a filename and URL, downloads that file and saves it to the downloads folder....
Read more >How to download file without full file path using Response ...
I am downloading the file using the below code. But, downloading the file is showing the full path of the filename. Example :...
Read more >[UiPath] Wait For Download activity - download files easily
Changing the path will not change where the file will be downloaded. It only says to the robot - take a look at...
Read more >Download File to Specific Path Without Move to Folder - Studio
I have searched throughout the forum without luck, all the answers are move the file from \Downloads which I believe is just complicating...
Read more >How to Specify Where Files Are Downloaded
By default, Chrome, Firefox and Microsoft Edge download files to the Downloads folder located at %USERPROFILE%\Downloads.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For any one who wants to the downloaded files to private or local storage
1.go to the android implementation and look for DownloadWorkder.java file
2.look for this function addFileToDownloadsApi21 and replace its content with this File newFile = new File(getApplicationContext().getFilesDir(), filename); return newFile;
and add this to bottom
fileApi21 = addFileToDownloadsApi21(filename); outputStream = new FileOutputStream(fileApi21, isResume);
Also comment out a big chunk of code in => if (status == DownloadStatus.COMPLETE) {}. condition
seems reckless but its a fix, you can file your files in the local storage
i am also facing the same issue, i wanted to download a file to private storage by path provided by getApplicationSupportDirectory but the package keeps downloading to downloads folder in the external storage