一個 Flutter 插件,可將支援的 URI 轉換為 Android 和 iOS 上的 File 物件。它讓開發者能透過將 URI 轉換為可用的 File 實例,從各種 URI 來源(如圖片或文件)存取檔案。在使用檔案選擇器、相機拍攝或外部檔案參考時特別有用。該插件透過抽象平台特定邏輯,簡化了跨平台應用中的檔案處理。
適用情境
將圖庫中的影像 URI 轉換為檔案
處理來自外部來源的文件路徑
處理來自攝影機的捕獲媒體
從共享儲存讀取檔案
與檔案選擇器外掛程式整合
支援從 URI 上傳檔案
主要特色
Android 與 iOS 的跨平台支援
簡單的 URI 轉檔案轉換
處理常見檔案類型
所需的設定最少
與原生檔案系統存取相容
與檔案選擇器整合相容
適合對象
需要從 URI 訪問檔案的應用程式
媒體處理工作流程
檔案上傳功能
影像和文件處理
使用檔案選擇器或相機的開發者
使用建議
僅支援 Android 和 iOS
需要檔案訪問的正確權限
僅限支援的 URI 方案
可能不適用於所有自訂或加密的 URI
取決於底層平台的實作
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
uri_to_file
A Flutter plugin for converting supported uri to file. Supports Android & iOS.
Supported Uri Schema
content:// (Android Only)
Schema supported by File.fromUri(uri)
Get started
Add dependency
dependencies:uri_to_file:^1.0.0
Super simple to use
import'dart:io';
import'package:uri_to_file/uri_to_file.dart';
Future<void> convertUriToFile() async {
try {
String uriString = 'content://sample.txt'; // Uri string// Don't pass uri parameter using [Uri] object via uri.toString().// Because uri.toString() changes the string to lowercase which causes this package to misbehave// If you are using uni_links package for deep linking purpose.// Pass the uri string using getInitialLink() or linkStreamFile file = awaittoFile(uriString); // Converting uri to file
} catch (e) {
print(e); // Exception
}
}
Important note
Don't pass uri parameter using [Uri] object via uri.toString(). Because uri.toString() changes the string to lowercase which causes this package to misbehave
If you are using uni_links package for deep linking purpose. Pass the uri string using getInitialLink() or linkStream
Check out the full example: https://pub.dev/packages/uri_to_file/example
Working example
Background
content:// (Android Only)
uri_to_file creates a temporary file using the content:// uri with the help of native channel that stores this file in the application directory.
All the others uri are handled by flutter sdk itself with the help of
File.fromUri(uri)
Copyright & License
MIT License
Features and bugs
Please file feature requests and bugs at the issue tracker.