搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。