flutter - 如果我将文件放在 getApplicationDocumentsDirectory() 目录中,文件将存储在哪里?它会增加应用程序的大小吗?
问题描述
Future<void> downloadFile() async{
Dio dio = Dio() ;
try{
var dir = await getApplicationDocumentsDirectory();
print('DIR is :${dir}');
await dio.download(pdfUrl, "${dir.path}/sample.pdf",onReceiveProgress: (rec,total){
print('rec:${rec},total:${total}');
setState(() {
downloading=true ;
progressString =((rec / total) * 100).toStringAsFixed(0) + "%" ;
});
});
}catch(e){
print(e);
}
setState(() {
downloading = false;
progressString = "Completed";
});
print("Download completed");
}
我想存储我下载的 pdf 以供离线使用,我该如何实现呢?如何保存在 downloads/(sample.pdf) 本地文件夹中,并且可以在离线时检索文件?
解决方案
在 iOS 上,这使用 NSDocumentDirectory API。如果数据不是用户生成的,请考虑改用 getApplicationSupportDirectory。
在 Android 上,这在上下文中使用 getDataDirectory API。如果数据旨在对用户可见,请考虑使用 getExternalStorageDirectory。
所以我不知道App size是什么意思?如果您将文件下载到应用程序的目录,这将明显增加应用程序缓存或其他大小,但不会增加 apk 大小。
推荐阅读
- mysql - 获取python mysql连接器执行的命令
- ruby-on-rails - 带有茧栏杆的嵌套表单在编辑时会重复子项目
- python - 如何使用 DataFrame & Index 创建表
- objective-c - 正则表达式的 NSPredicate 与“№”字符不正确
- python - grpc_tools.protoc generates python files with broken imports
- java - Using Java APIs to connect to Kerberos secured HBase
- android - Kotlin 在动态添加的编辑文本上设置属性
- flutter - how to use my async call (Future
) as a String variable for my queries - python - Remove non-numeric values in column using Python
- r - Group_by and summarize behave strangely and do not provide expected results