搜尋套件、儲存庫與 APP 分類

uri_to_file 封面
套件詳情v1.0.0

uri_to_file

一個用於將支援的 URI 轉換為檔案的 Flutter 插件。支援 Android 與 iOS。

AndroidiOS
近 30 天下載
5210
喜歡數
44
Pub 分數
160

安裝套件

flutter pub add uri_to_file

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,可將支援的 URI 轉換為 Android 和 iOS 上的 File 物件。它讓開發者能透過將 URI 轉換為可用的 File 實例,從各種 URI 來源(如圖片或文件)存取檔案。在使用檔案選擇器、相機拍攝或外部檔案參考時特別有用。該插件透過抽象平台特定邏輯,簡化了跨平台應用中的檔案處理。

適用情境

  • 將圖庫中的影像 URI 轉換為檔案
  • 處理來自外部來源的文件路徑
  • 處理來自攝影機的捕獲媒體
  • 從共享儲存讀取檔案
  • 與檔案選擇器外掛程式整合
  • 支援從 URI 上傳檔案

主要特色

  • Android 與 iOS 的跨平台支援
  • 簡單的 URI 轉檔案轉換
  • 處理常見檔案類型
  • 所需的設定最少
  • 與原生檔案系統存取相容
  • 與檔案選擇器整合相容

適合對象

  • 需要從 URI 訪問檔案的應用程式
  • 媒體處理工作流程
  • 檔案上傳功能
  • 影像和文件處理
  • 使用檔案選擇器或相機的開發者

使用建議

  • 僅支援 Android 和 iOS
  • 需要檔案訪問的正確權限
  • 僅限支援的 URI 方案
  • 可能不適用於所有自訂或加密的 URI
  • 取決於底層平台的實作

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

uri_to_file

Pub

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 linkStream

    File file = await toFile(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

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.

所屬分類

依賴

依賴清單 1 項

  • plugin_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案