简体   繁体   English

Flutter 如何使用path_provider获取本地下载文件夹

[英]Flutter how get local download folder with path_provider

At the moment i build a chat similar in wahtsapp.目前我在 wahtsapp 中建立了一个类似的聊天。 I would like upload some local files (pdf, txt, image...).我想上传一些本地文件(pdf、txt、图片...)。

Like this:像这样:

在此处输入图像描述

I try to get the local files via path_provider.我尝试通过 path_provider 获取本地文件。 But i dont get access to download folder.但我无法访问下载文件夹。

My problem: I don't know how i can access the dowload folder with path_provider.我的问题:我不知道如何使用 path_provider 访问下载文件夹。

See my code:看我的代码:

//load local files from download folder
_loadLocalFile() async {
  //absoulute path to download file 
  var file = io.Directory('/storage/emulated/0/Download/')
      .listSync(); //use your folder name insted of resume.
  //console output -> []

  //other try to get download folder 
  List<io.Directory>? documents = await getExternalStorageDirectories();
//console output -> [Directory: '/storage/emulated/0/Android/data/de.securebuy.securebuy/files', Directory: '/storage/1BEC-0908/Android/data/de.securebuy.securebuy/files']

  print(documents.toString());
}

I also add to AndroidManifest following rules:我还向 AndroidManifest 添加了以下规则:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE”/>

Anyone have a idea how i can build a function similar in image?任何人都知道我如何构建一个图像相似的 function? Is that possible?那可能吗?

Many thx非常感谢

till now, pathprovider isn't going to let you in downloads file, so if you are on android you can just write the downloads directory, else using android_path_provider it is a null-safety package and you can accsess it via: var downloadsPath = await AndroidPathProvider.downloadsPath;到目前为止, pathprovider不会让你下载文件,所以如果你在 android 上,你可以只写下载目录,否则使用android_path_provider它是一个空安全 package 你可以通过以下方式访问它: var downloadsPath = await AndroidPathProvider.downloadsPath; , on ios you can get only the app directory cuase ios makes it's own file for every app thus we use 'pathprovider' with Directory appDocDir = await getApplicationDocumentsDirectory(); ,在 ios 上,您只能获得应用程序目录,因为 ios 为每个应用程序创建了自己的文件,因此我们将“pathprovider”与Directory appDocDir = await getApplicationDocumentsDirectory();

Update: i see what you are trying to achieve and this is not what pathprovider pcakage is used for, you have to use file_picker , read thier docs, i thinks that this is what you need更新:我看到你想要实现的目标,这不是pathprovider pcakage 的用途,你必须使用file_picker ,阅读他们的文档,我认为这就是你需要的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM