How to Upload Large Video Files Efficiently Using Chunking

December 2, 2024
10 Min
Video Engineering
Jump to
Share
This is some text inside of a div block.

What is chunking and why does it matter for large file uploads?

Chunking is a method of splitting large files into smaller, manageable pieces, or "chunks," before uploading them. These chunks are uploaded sequentially or in parallel, and once all pieces reach the server, they are reassembled into the original file. This technique optimizes file uploads, making them faster, more reliable, and less prone to failure.

How chunking works: Step-by-Step process

  1. Divide and conquer: A large file (e.g., a 10GB video) is split into smaller chunks, like 5MB or 10MB each.
  2. Resilient transfers: If one chunk fails to upload, only that part is retried instead of restarting the entire process.
  3. Progressive completion: Chunks that successfully upload are stored, so any interruptions don’t erase previous progress.
  4. Reassembly: Once all chunks are uploaded, the server combines them to recreate the original file.

Chunking is widely used in modern applications like cloud storage platforms (Google Drive, Dropbox), video streaming services, and even APIs like Filestack and AWS S3 for efficient file handling. It’s particularly valuable in environments with slow or unstable networks, ensuring users can resume interrupted uploads without frustration.

The drawbacks of uploading large files without chunking

Unstable internet connections:

Imagine uploading a 5GB video for a client presentation using a spotty mobile network. Halfway through, the network drops for just a few seconds. Without chunking, the upload fails, forcing you to restart the entire process from scratch.

Time-sensitive projects:

Consider an online video editor where users upload raw footage. A creator working on a deadline uploads a single 20GB file. The process takes hours, and a server timeout occurs just before completion. Without chunking, the user misses the deadline, and your application earns a poor reputation.

High-traffic events:

During live sports events, fans upload large video clips to share on social platforms. Servers receive thousands of large file uploads simultaneously. Without chunking, server overloads lead to failures and long wait times, frustrating users and damaging the platform's credibility.

Data backup systems:

In cloud backup solutions, users try to upload a folder containing large video files. A single large file fails to upload due to a network interruption, leaving the backup incomplete. Without resumability, the user’s trust in the service diminishes.

Gaming industry challenges:

Gamers often upload gameplay videos to streaming platforms. Without chunking, any interruption during a large file upload caused by power cuts or system crashes results in wasted time and resources. Chunking, in contrast, could save hours by resuming from the last successful point.

Comparing performance: Uploading with vs without chunking

Chunking greatly enhances the performance of large file uploads by addressing key challenges like interruptions, speed, and server strain.

Reduced failure rates

Traditional uploads are highly vulnerable to network interruptions. If a connection drops, the entire upload must restart. With chunking, only the failed part needs to be re-uploaded, ensuring the process is far more resilient and reliable.

Faster upload speeds

Chunking allows multiple parts of a file to upload simultaneously, maximizing network efficiency. Unlike single-threaded uploads, which can be slow and time-consuming, chunking accelerates the process without compromising stability.

Lower server strain

Uploading large files in one go places heavy loads on servers, especially during peak usage. By breaking files into smaller chunks, chunking reduces server stress, enabling smoother operations and better scalability for platforms.

Metric Without Chunking With Chunking
Failure Rate Up to 30% Reduced by 95%
Upload Time (for 5GB) ~3 hours ~1 hour (parallel)
Server Load (High Traffic) Overloads & Crashes Reduced Server Load
Abandonment Rate 70% for long uploads 10% (Improved Progress)

In these scenarios, chunking resolves the headaches by splitting files into smaller parts, enabling resumable uploads, minimizing server strain, and improving user experience. It’s not just a technical enhancement—it’s a lifesaver in the real world.

Benefits of chunking in file uploads

The graph compares how Filestack, Hivo, and Google Drive/Dropbox benefited from chunking technology across three areas:

Failure rate reduction (Blue bars)

  • Filestack and Hivo show almost complete elimination of upload failures (~95%).
  • Google Drive/Dropbox shows a lower but still significant reduction in failures (~40%).

Upload speed improvement (Green bars)

  • All platforms see a ~30-40% increase in upload speeds due to parallel uploads enabled by chunking.

User satisfaction improvement (Red bars)

  • Hivo and Google Drive/Dropbox report higher user satisfaction (~40%), while Filestack slightly trails (~30%).

Chunking clearly improves reliability, speed, and user experience across all these platforms.

Chunking in action: How major platforms use It

  • Media uploads:
    Platforms like YouTube, Vimeo, and Instagram use chunking to upload videos and images reliably, even on slow or unstable networks. It ensures users can resume interrupted uploads without losing progress.
  • Cloud storage services:
    Services like Google Drive, Dropbox, and OneDrive leverage chunking for uploading large files, ensuring faster and more reliable transfers while managing server load effectively.
  • Data transfer applications:
    Chunking is essential for apps like WeTransfer and AWS S3, which handle massive file transfers by breaking them into manageable chunks, enabling resumable uploads and error recovery.
  • Live streaming and broadcasting:
    Video streaming platforms use chunking to split live feeds into smaller segments for real-time transmission, improving latency and playback quality.
  • Backup and restore systems:
    Backup tools like CrashPlan or Time Machine use chunking to transfer large datasets incrementally, allowing efficient backups and restorations over time.
  • Software distribution:
    Applications like game updates or large software patches use chunking to ensure smooth downloads, avoiding failures due to network disruptions.

How to implement chunking using Fastpix Upload SDK:

What is upload SDK:

This SDK allows for efficient uploading of large files directly from the browser by splitting them up into smaller chunks. It also gives the functionality to pause and resume uploads. Although the SDK is developed in TypeScript, we are releasing only the JavaScript output as an npm package for now. Support for TypeScript users will be included in a later version.

Please note that this is an SDK tailored for use with FastPix and is not a general-purpose upload solution.

Features:

Chunking: Files are automatically divided into smaller segments, with a configurable default size of 16MB per chunk.

Pause and resume: This is one such feature provided to pause an upload and resume later.

Retry mechanism : Uploading may fail if there are temporary network failures. Using an exponential backoff strategy, each chunk is retried up to five times to automatically recover from such issues.

Lifecycle event listeners : Developers can be notified about different upload lifecycle events and can give instantaneous feedback to the users who are uploading.

Error handling and reporting : The SDK has robust error handling capabilities so that upload failures can be handled gracefully, and the users are informed about the same.

Customizability : The size of the chunk and the number of retries can be preset at developers' discretion based on specific requirements and network conditions.

Installation:

To install the SDK, you can use npm or your favourite node package manager :

npm i @fastpix/uploader

Basic usage:

To get started with SDK, you will need a signed URL.

To make API requests, 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.

import:

1import {Uploader} from "@fastpix/uploader" 

Integration:

1const fileUploader = Uploader.init({ 
2    endpoint: 'https://example.com/signed-url', // Replace with the signed URL. 
3    file: mediaFile, // Provide the media file you want to upload. 
4    chunkSize: 5120, // Specify the chunk size in kilobytes (KB). Minimum allowed chunk size is 5120KB (5MB). 
5    
6    // Additional optional parameters can be specified here as needed 
7}) 

Monitor the upload progress through lifecycle events:

1// Track upload progress 
2fileUploader.on('progress', event => {  
3    console.log("Upload Progress:", event.detail);  
4});  
5
6// Handle errors during the upload process 
7fileUploader.on('error', event => {  
8    console.error("Upload Error:", event.detail.message);  
9});  
10  
11// Trigger actions when the upload completes successfully 
12fileUploader.on('success', event => {  
13    console.log("Upload Completed");  
14});  
15  
16// Track the initiation of each chunk upload 
17fileUploader.on('attempt', event => {  
18    console.log("Chunk Upload Attempt:", event.detail);  
19});  
20
21// Track failures of each chunk upload attempt 
22fileUploader.on('chunkAttemptFailure', event => {  
23    console.log("Chunk Attempt Failure:", event.detail);  
24});  
25  
26// Perform an action when a chunk is successfully uploaded 
27fileUploader.on('chunkSuccess', event => {  
28    console.log("Chunk Successfully Uploaded:", event.detail);  
29});  
30
31// Triggers when the connection is back online 
32fileUploader.on('online', event => {  
33    console.log("Connection Online");  
34});  
35  
36// Triggers when the connection goes offline 
37fileUploader.on('offline', event => {  
38    console.log("Connection Offline");  
39}); 

Managing uploads

You can control the upload lifecycle with the following methods:

Pause an Upload:

1fileUploader.pause(); // Pauses the current upload

Resume an Upload:

1fileUploader.resume(); // Resume the current upload 

Abort an Upload:

1fileUploader.abort(); // Abort the current upload 

Parameters accepted

This SDK supports the following parameters:

endpoint (required): The URL endpoint where the file will be uploaded.

file (required): The file object that you want to upload.

chunkSize (optional): Size of each chunk in kilobytes (KB). Default is 16 MB (16384 KB), with a minimum of  5 MB (5120 KB) and a maximum of 500 MB (512000 KB).

maxFileSize (optional): The maximum file size allowed for upload, specified in kilobytes (KB). This helps prevent excessively large uploads.

retryChunkAttempt (optional):  Number of retries per chunk in case of failure. Default is 5 retries.

delayRetry (optional): Delay between retry attempts (in milliseconds) after a chunk upload fails. Default is 1000 ms.

How Fastpix handles video chunking automatically

After using the Fastpix Upload SDK to upload a video, the system processes the file by splitting it into smaller chunks. These chunks enable efficient streaming and playback. Here's an example of the response you receive after uploading and playing the video through Fastpix:

example:

1#EXTM3U 
2
3#EXT-X-VERSION:6 
4
5## Generated with https://github.com/shaka-project/shaka-packager version v3.2.0-53b8668-release 
6
7#EXT-X-TARGETDURATION:4 
8
9#EXT-X-PLAYLIST-TYPE:VOD 
10
11#EXT-X-MAP:URI="https://cdn.fastpix.io/media/642239c1-c34b-4f86-bda5-7fe3ab513a3b/video_360/init.mp4?workspaceId=33a4fe1e-14a9-4903-8938-7ce41a4617d4&resolution=640x360&duration=null" 
12
13#EXTINF:4.000, 
14
15https://cdn.fastpix.io/media/642239c1-c34b-4f86-bda5-7fe3ab513a3b/video_360/1.m4s?workspaceId=33a4fe1e-14a9-4903-8938-7ce41a4617d4&resolution=640x360&duration=4.000 
16
17#EXTINF:4.000, 
18
19https://cdn.fastpix.io/media/642239c1-c34b-4f86-bda5-7fe3ab513a3b/video_360/2.m4s?workspaceId=33a4fe1e-14a9-4903-8938-7ce41a4617d4&resolution=640x360&duration=4.000 
20
21#EXTINF:2.000, 
22
23https://cdn.fastpix.io/media/642239c1-c34b-4f86-bda5-7fe3ab513a3b/video_360/3.m4s?workspaceId=33a4fe1e-14a9-4903-8938-7ce41a4617d4&resolution=640x360&duration=2.000 
24
25#EXT-X-ENDLIST 

Explanation

Automatic chunking:

  1. Fastpix converts the uploaded video into small, manageable segments (1.m4s, 2.m4s, etc.).
  2. Each chunk has its duration (e.g., 4 seconds) specified with #EXTINF.

Smooth playback:

  1. The #EXTM3U playlist ensures the video player fetches and plays these chunks seamlessly.
  2. The #EXT-X-MAP initializes playback, ensuring the player understands the video format.

Optimized streaming:

  1. Chunking reduces buffering and allows adaptive streaming, adjusting video quality based on network conditions.

Why chunking is essential:

Chunking helps scale video playback for different users and devices by:

  • Reducing latency: Users start watching even before the full video loads.
  • Enhancing reliability: If one chunk fails to load, the rest of the video remains unaffected.
  • Improving efficiency: Allows parallel uploads and downloads.

With Fastpix automating this process, developers can focus on building their applications without worrying about video optimization.

Conclusion

Chunking is more than a technique to handling large video uploads effectively. Without chunking, developers encounter unreliable uploads, wasted resources, and dissatisfied users. It breaks files into manageable chunks, ensuring smoother uploads, quicker transfers, and a significantly enhanced user experience. With chunking features like resumable uploads, error handling, and customizable chunk size, the Fastpix Upload SDK simplifies implementation for developers. The Fastpix Upload SDK provides a stable and efficient way of managing big files, which is, therefore, a tool required for developers who have the intent to engage in modern applications with lots of media files. With Fastpix, through chunking, comes the potential for high performance, reliability, and user satisfaction in managing the file upload process.

Get Started

Enjoyed reading? You might also like

Try FastPix today!

FastPix grows with you – from startups to growth stage and beyond.