gpt4 book ai didi

flutter - 如何在 Flutter 中获取使用图像选择器插件选择的图像的原始路径而不是复制到缓存?

转载 作者:行者123 更新时间:2023-12-03 22:29:31 30 4
gpt4 key购买 nike

我正在制作一个 Android 应用程序,并且在使用图像选择器插件时;

final pickedFile = await ImagePicker().getImage(source: ImageSource.gallery);
File image = File(pickedFile.path);
“图像”是应用程序缓存中原始图像的副本,但是,我想直接使用原始图像的路径将其保存在我的应用程序中,因为我不希望应用程序缓存大小增加。我看到不推荐使用的方法“pickImage”完成了这一点(不复制到缓存),但新的“getImage”似乎自动复制,并且“图像的路径”是缓存图像的路径。
如何在不缓存的情况下仅获取所选图像的原始路径? (我假设使用原始文件的路径仍然可以使用 FileImage(File(originalPath)) 在应用程序中显示它,这是正确的假设吗?)

最佳答案

在 iOS 上,永远不可能检索原始路径,而在 Android 上,只有在 SDK 30 之前才有可能。
来自 FAQ file_picker 插件,

Original paths were possible until file_picker 2.0.0 on Android, however, in iOS they were never possible at all since iOS wants you to make a cached copy and work on it. But, 2.0.0 introduced scoped storage support (Android 10) and with and per Android doc recommendations, files should be accessed in two ways:


  • Pick files for CRUD operations (read, delete, edit) through files URI and use it directly — this is what you actually want but unfortunately isn’t supported by Flutter as it needs an absolute path to open a File descriptor;

  • Cache the file temporarily for upload or similar, or just copy into your app’s persistent storage so you can later access it — this is what’s being done currently and even though you may have an additional step moving/copying the file after first picking, makes it safer and reliable to access any allowed file on any Android device.

关于flutter - 如何在 Flutter 中获取使用图像选择器插件选择的图像的原始路径而不是复制到缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63309590/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com