Flutter how to download files and save it into phone storage - flutter

I'm writing a flutter app in which I want to download files from an URL when I write this URL in my browser the file download
I want to do the same with flutter and I want to store the file in the phone local storage
I tried with dio and path provider without any result it show me that the file is downloaded but I do not find it in local storage this is my method
Future <void> dow5tn()async{
var dir=await getApplicationDocumentsDirectory();
Dio dio=Dio();
dio.download('http://192.168.43.24:27017/api/posts/uknoww','${dir.path}/filename.pdf');
}

Try this GitHub Repos
It's work for me

Related

Flutter - Where should I save downloaded files?

I am building a flutter app (iOS/Android/MacOS/Windows/Web) which is able to download files, selected by the user. But where should I save those files? On MacOS/Windows its easy using path_provider and get the path of the downloads folder.
But where should I save the files on the other platforms? The downloads folder would be perfect because the users are able to use those files (.pdf) even without using the app, so the files are not app specific.
If you wish to save in download directory you can use
Directory appDownloadDir = await getDownloadsDirectory();
String appDownloadPath = appDownloadDir.path;
Or
getExternalStorageDirectory()//android
getApplicationDocumentsDirectory()// ios doesnt support access to download folder

How can I save a local file into assets folder in Flutter

My flutter desktop application takes a local file (audio/video/image) as user input. Now I need to save it to somewhere for later usage. So that even if the device changes the application can still access them using relative path.
What I want to do is copy this file to assets folder using file.copy method. But how can I get the assets folder's directory? I don't want to hardcode assets folder's absolute path. Is there any way to copy files into assets folder using relative path?
Or any alternate way to do the task?
assets is read-only. Use documents directory where the application can store files that only it can access.
final directory = await getApplicationDocumentsDirectory();
See Read and write files for details.

how to get access to the path directory in FLUTTER WEB as final dir = await getApplicationDocumentsDirectory(); doesn't seem to work

how to get access to the path directory in FLUTTER WEB as final dir = await getApplicationDocumentsDirectory(); doesn't seem to work ... This is required to generate pdf invoice.
The web does not have internal file storage or acces a device,
information can only be stored through cookies or a database such as
Indexeddb.
You can create the invoice by creating the file with dart code and then send it or share it by some means
Another way would be to create it through a canvas.
i just uploaded the file to fireStore and then fetched it then again launched it using http package. or i found out we can launch the url also with launcher package.

Can not find the cached files (through flutter_cache_manager) on device

I am using this code to cache files on my local storage:
var audioFile = await DefaultCacheManager().getSingleFile('fileUrl');
I need to physically access the file to see if the user can access it from the file manager. When I run the app, the files are being cached. But I can not find the path where the files are cached on the device.
This is the address that I get on debug mode:
"/data/user/0/{my_package_name}/cache/libCachedImageData/3a65ece0-5366-11eb-91e0-0f0ba53cd292.mp4"
But there is no such path on my device.
It is a path to a "hiden" folders on your device. You can navigate to this path with root privileges or get (and navigate) the data by tutorials like this. Also you can find this folders without any permissions on Android emulator from File Explorer tab in Android Studio.

how to open any network file on Flutter?

Currently, I am using open_file: ^3.0.1 plugin for an open local disk file. But How to open any network file? I store the file on Firebase Storage and I read URL.
for Local File open
OpenFile.open(path);
I stored any type of file to firebase storage... And also I load all files from firebase storage. Users can open(view) these particular files
Example:
Url 1 = https://... - image
Url 2 = https:// - pdf
Url 3 = https:// -
word
One way of accessing files from a network is downloading the file to a temporary directory on your device. You can use flutter_downloader to achieve this. Once downloaded, you can read the file from the path.
But since you're using Firebase Cloud Storage, follow this guide to download the file. If you wish to only temporarily store the file, you can delete the file when not in use anymore.