Set up resumable uploads for Flutter
The FastPix Flutter Resumable Uploads SDK helps you efficiently upload large files from Flutter apps by splitting them into chunks and also gives you the ability to pause and resume your uploads.
How resumable uploads work through chunking
Resumable uploads can be effectively handled through a technique called chunking. This method involves breaking down large files into smaller, more manageable pieces, or “chunks.” Here’s how chunking works:
- Divide the file: Large files are split into smaller, manageable chunks (e.g., 16 MB by default).
- Upload individually: Each chunk is uploaded separately. If a chunk fails, only that specific chunk needs to be re-uploaded.
- Resume capability: If the upload is interrupted, you can resume from the last successfully uploaded chunk instead of starting over.
This approach is important because:
- It reduces the risk: Uploading smaller chunks minimizes the risk of failure. If a chunk fails to upload due to network issues, only that specific chunk needs to be re-uploaded, not the entire file.
- Improves performance: Smaller chunks can be uploaded more quickly and efficiently, especially on slower connections, as they require less time to transfer.
- Easier management: Chunking allows for better tracking of upload progress, making it easier to implement features like pause and resume.
Step 1: Install the Flutter SDK
Add the dependency to yourpubspec.yaml
Add FastPix’s Flutter library to the dependencies block of your pubspec.yaml file.
Install dependencies
Run the following command to install the dependencies:
Step 2: Create an upload URL
In order to upload a video, you will need a signed upload URL.
To get this signed URL, you’ll need a valid Access Token and Secret Key. See the Basic Authentication Guide for details on retrieving these credentials.
Once you have your credentials, use the Upload media from device API to generate a signed URL for uploading media. After fetching the the signed URL you can continue with integrating the SDK into your application.
The example below gives you an idea about how to get the signed URL using the upload media from device API. You can use the example directly or also refer to our upload videos directly guide.
Step 3: Start your upload
The Flutter SDK provides a builder pattern for easy configuration and initialization:
Builder configuration options
Step 4: Monitor upload events
The SDK provides comprehensive callback methods to monitor upload progress and handle various events:
Progress model
The progress callback provides a ProgressModel with the following properties:
uploadPercentage: Progress percentage (0.0 - 100.0)currentChunkIndex: Current chunk being uploadedtotalChunks: Total number of chunksstatus: Current upload status (e.g., “splitting_chunks”, “uploading_chunks”, “completed”)fileSize: Total file size in bytesuploadedBytes: Number of bytes uploaded so far
Step 5: Manage video uploads
You can control the upload lifecycle with the following methods:
Pause an upload
Resume an upload
Abort an upload
Check upload status
Detailed usage example
The following example gives an overview of integrating the FastPix Flutter Uploads SDK into your project, enabling you to build a fully customized upload interface:
Features
Core features
- Chunking: Files are automatically split into chunks (default chunk size is 16MB).
- Pause and resume: Allows temporarily pausing the upload and resuming after a while.
- Retry: Uploads might fail due to temporary network failures. Individual chunks are retried with exponential backoff to recover automatically from such failures.
- Lifecycle event listeners: Provides real-time feedback through various upload lifecycle events.
- Error handling: Comprehensive error management to notify users of issues during uploads.
- Customizability: Options to customize chunk size and retry attempts.
Advanced features
- Network health monitoring: Automatically detects network connectivity changes and handles offline scenarios.
- Upload lock management: Prevents multiple concurrent uploads from the same service instance.
- Progress tracking: Detailed progress reporting with chunk-level information.
- File validation: Built-in file size and format validation.
- Memory efficient: Streams file chunks without loading the entire file into memory.
BEST PRACTICES
Chunk Size: Use appropriate chunk sizes based on your target platform and network conditions. 16MB is a good default for most scenarios.
Error Handling: Always implement proper error handling to provide meaningful feedback to users.
Progress Updates: Use progress callbacks to update your UI and keep users informed about upload status.Network Monitoring: The SDK automatically handles network connectivity changes, but you may want to add additional network monitoring for better UX.
Memory Management: For very large files, consider implementing additional memory management strategies.
Retry Configuration: Adjust retry settings based on your network environment and requirements.
Troubleshooting common issues
Upload fails immediately
Check if the signed URL is valid and not expired.
Chunks fail to upload
Verify network connectivity and adjust retry settings.
Memory issues with large files
The SDK handles memory efficiently, but ensure your app has sufficient memory allocation.
Progress not updating
Make sure you’re properly implementing the progress callback.
DEBUG INFORMATION
Enable debug logging to get detailed information about upload operations.
- The SDK automatically logs debug information when running in debug mode.
- Check the console output for detailed upload information
For more information and support, contact us.