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

套件詳情v1.0.2

tus_client

一個用於 Dart 的 tus 客戶端,允許使用 tus 協議進行可恢復上傳。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
145
喜歡數
25
Pub 分數
140

安裝套件

flutter pub add tus_client

套件介紹

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

tus_client 套件是 tus 協定的 Dart 實作,可在各種平台實現可恢復的檔案上傳。它透過將大檔案分割成多個區塊並恢復中斷的傳輸,讓使用者能可靠地上傳大型檔案。該客戶端支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 與 Linux。專為穩健性與效率設計,能在網路中斷時妥善處理,並確保上傳過程中的資料完整性。非常適合需要安全、可擴展檔案傳輸功能的應用程式。

適用情境

  • 大檔案上傳
  • 離線優先檔案傳輸
  • 雲端儲存整合
  • 上傳過程中的進度追蹤
  • 恢復中斷的上傳

主要特色

  • 可恢復上傳
  • 跨平台支援
  • 分塊檔案傳輸
  • 上傳進度監控
  • 失敗時自動重試

適合對象

  • 檔案密集型應用
  • 具有上傳需求的移動和網頁應用
  • 需要可靠數據傳輸的應用程式
  • 使用tus協議的開發人員
  • 與 tus 客戶端整合的後端服務

使用建議

  • 需要一個相容 tus 的伺服器
  • 僅限檔案上傳使用情境
  • 可能需要為自定標頭進行額外設定
  • 不適用於串流或即時資料
  • 依賴穩定的互聯網連接以獲得最佳效能

原始 README

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

A tus client

Pub Version Build Status codecov


A tus client in pure dart. Resumable uploads using tus protocol

tus is a protocol based on HTTP for resumable file uploads. Resumable means that an upload can be interrupted at any moment and can be resumed without re-uploading the previous data again. An interruption may happen willingly, if the user wants to pause, or by accident in case of a network issue or server outage.

Usage

import 'package:cross_file/cross_file.dart' show XFile;

// File to be uploaded
final file = XFile("/path/to/my/pic.jpg");

// Create a client
final client = TusClient(
    Uri.parse("https://master.tus.io/files/"),
    file,
    store: TusMemoryStore(),
);

// Starts the upload
await client.upload(
    onComplete: () {
        print("Complete!");

        // Prints the uploaded file URL
        print(client.uploadUrl.toString());
    },
    onProgress: (progress) {
        print("Progress: $progress");
    },
);
Using Persistent URL Store

This is only supported on Flutter Android, iOS, desktop and web. You need to add to your pubspec.yaml:

dependencies:
  tus_client: ^1.0.2
  tus_client_file_store: ^0.0.3
import 'package:path_provider/path_provider.dart';
import 'package:tus_client_file_store/tus_client_file_store.dart' show TusFileStore;
import 'package:path/path.dart' as p;

// Directory the current uploads will be saved in
final tempDir = (await getTemporaryDirectory()).path;
final tempDirectory = Directory(p.join(tempDir, "tus-uploads"));

// Create a client
final client = TusClient(
    Uri.parse("https://example.com/tus"),
    file,
    store: TusFileStore(tempDirectory),
);

// Start upload
await client.upload();
Adding Extra Headers
final client = TusClient(
    Uri.parse("https://master.tus.io/files/"),
    file,
    headers: {"Authorization": "..."},
);
Adding extra data
final client = TusClient(
    Uri.parse("https://master.tus.io/files/"),
    file,
    metadata: {"for-gallery": "..."},
);
Changing chunk size

The file is uploaded in chunks. Default size is 512KB. This should be set considering speed of upload vs device memory constraints

final client = TusClient(
    Uri.parse("https://master.tus.io/files/"),
    file,
    maxChunkSize: 10 * 1024 * 1024,  // chunk is 10MB
);
Pausing upload

Pausing upload can be done after current uploading in chunk is completed.

final client = TusClient(
    Uri.parse("https://master.tus.io/files/"),
    file
);

// Pause after 5 seconds
Future.delayed(Duration(seconds: 5)).then((_) =>client.pause());

// Starts the upload
await client.upload(
    onComplete: () {
        print("Complete!");
    },
    onProgress: (progress) {
        print("Progress: $progress");
    },
);

Example

For an example of usage in a Flutter app (using file picker) see: /example

Maintainers

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。