搜索插件、代码仓与 APP 分类

GitHub 代码仓jjmutumi/tus_client

tus_client

Dart 的 tus 客户端

tus_client 项目封面
星标
34
复刻
53
最近推送(UTC)
2024年7月11日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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

Joseph Mutumi GitHub avatar
GitHub 作者

Joseph Mutumi ↗

The most humble stone is part of the grandest tower.

Victorium HoldingsKampala, Uganda
语言DartHTMLSwiftKotlinShellObjective-C

此仓库发布的插件

使用的依赖

依赖清单 7 项

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗