flutter_upload_manager 1.0.1 copy "flutter_upload_manager: ^1.0.1" to clipboard
flutter_upload_manager: ^1.0.1 copied to clipboard

A Flutter package for managing file uploads with chunked upload support and resume capability.

flutter_upload_manager #

A Flutter package for managing file uploads with chunked upload support and resume capability. This package supports null safety and is compatible with the latest Flutter versions.

Features #

  • Chunked Upload: Split large files into smaller chunks for efficient uploading
  • Resume Capability: Resume interrupted uploads from where they left off
  • Progress Tracking: Monitor upload progress with percentage updates
  • Null Safety: Full null safety support for modern Dart/Flutter development
  • Flexible Storage: Customizable state storage for upload progress
  • Multi-threaded Uploads: Support for concurrent chunk uploads

Getting Started #

Prerequisites #

  • Flutter SDK >= 3.10.0
  • Dart SDK >= 3.0.0

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_upload_manager: ^1.0.0

Usage #

  1. Implement the required delegates:
class MyStorage implements StateDelegate {
  @override
  Future<void> saveState(String filePath, UpState state) async {
    // Save upload state to persistent storage
  }

  @override
  UpState? loadByPath(String filePath) {
    // Load upload state from persistent storage
    return null;
  }

  @override
  Future<void> removeState(String filePath) async {
    // Remove upload state from storage
  }
}

class MyUploader implements UploadDelegate {
  @override
  void initUpload(UpState state) {
    // Initialize upload process
  }

  @override
  Future<UpState> directUpload(String fileKey, UpState state, List<int> fileData) async {
    // Handle direct upload for small files
    return state;
  }

  @override
  Future<UpState> initPartialUpload(String fileKey, UpState state) async {
    // Initialize multipart upload
    return state;
  }

  @override
  Future<String> uploadPart(String fileKey, UpState state, int idx, List<int> chunkData) async {
    // Upload a single chunk
    return 'etag';
  }

  @override
  Future<UpState> completePart(String fileKey, UpState state) async {
    // Complete multipart upload
    return state;
  }

  @override
  void updatePercentage(int total, int success) {
    // Update upload progress
    print('Progress: $success/$total');
  }

  @override
  void onFinished(UpState state) {
    // Handle upload completion
    print('Upload finished');
  }
}
  1. Use the upload manager:
final storage = MyStorage();
final uploader = MyUploader();
final manager = UpManager(uploader, storage);

// Upload a file
await manager.upfile(
  'my-file.txt',
  fileData,
  fileSize,
  chunkSize: 1024 * 1024, // 1MB chunks
  p: 2, // 2 concurrent uploads
);

API Reference #

UpManager #

The main class for managing file uploads.

  • upfile(String fileKey, Uint8List fileData, int fileSize, {int chunkSize, int p}): Upload a file with optional chunk size and concurrency settings

UpState #

Represents the state of an upload operation.

  • uploadId: Unique identifier for the upload
  • filePath: Path to the file being uploaded
  • fileSize: Size of the file in bytes
  • chunks: List of chunk states
  • successCount: Number of successfully uploaded chunks
  • url: Upload URL

ChunkState #

Represents the state of a single upload chunk.

  • id: Chunk identifier
  • startIdx: Start index in the file
  • endIdx: End index in the file
  • state: Upload state (0=uploading, 1=success, 2=failed)
  • etag: ETag from upload response

Migration from v0.x #

This version includes breaking changes for null safety support:

  • All nullable fields are now properly typed with ?
  • Constructor parameters are now required where appropriate
  • Method signatures have been updated for better type safety
  • Removed deprecated syntax and patterns

License #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
140
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for managing file uploads with chunked upload support and resume capability.

Homepage

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

flutter

More

Packages that depend on flutter_upload_manager