Set up resumable uploads for iOS
The FastPix iOS Upload SDK helps you to upload videos from your iOS app to the FastPix platform. It’s built to handle large files, manage network interruptions, and give you full control over the upload process all with minimal setup.
Why use the FastPix iOS upload SDK?
The FastPix iOS SDK is built for reliability, flexibility, and performance when uploading large video files from your app. Key features include:
- Chunked uploads: Automatically breaks large videos into smaller chunks for smoother transfers. You can customize the chunkSize to fit your app’s needs.
- Resumable uploads: If the network drops or the app closes, uploads resume from where they left off no need to start over.
- Pause and resume support: Give users control by allowing uploads to be paused mid-way and resumed later without data loss.
Step 1: Install the SDK
Prerequisites
- An existing Xcode project.
- Swift Package Manager (SPM) installed on your development machine.
Installing using Swift Package Manager (SPM)
- Open your Xcode project.
- Navigate to the “File” menu and select “Swift Packages” > “Add Package Dependency…”
- In the search bar, enter the URL for the FastPixUploadSDK repository:
https://github.com/FastPix/iOS-Uploads - Locate the desired version of the SDK. By default, the latest version will be displayed.
- Click “Add Package” to integrate the FastPixUploadSDK into your project.
Importing the SDK package
Once the package dependency is added, you can import the FastPixUploadSDK module:
Step 2: Create an upload URL
To fully integrate the FastPixUploadSDK into your iOS application, follow these steps:
Generating a signed direct upload URL
- Implement server-side logic to interact with FastPix’s API to create a signed URL.
- You will need an access token from FastPix (Token ID and Secret Key), generated in your FastPix dashboard.
- After making the request, FastPix returns a signed URL used for secure uploads.
Step 3: Start your upload
- Uploader initialization:
var uploader = Uploads()prepares for a new session. - Async upload trigger: Runs inside
Taskfor async handling. - Signed URL retrieval: Calls
createDirectUpload()from your backend. - File upload start: Uses
uploadFile()to initiate upload.
Add this code in your upload functionality module within your iOS app project. It could be in a service layer or directly within a controller or view model where the upload operation is triggered, ensuring it is properly integrated with your app’s workflow.
Step 4: Track progress with progressHandler
You can show real-time progress updates during the upload by using the progressHandler callback provided by the SDK. This allows you to update progress bars, display percentage completion, and notify users when the upload finishes.
Step 5 : Pause and resume uploads
Pause and resumable uploads allow you to temporarily pause a file upload and then pick it up later from where it left off. This is especially useful for large video files that may be interrupted due to network issues or app crashes.
- Create an uploader object
- Call pause() to temporarily stop the upload
- Call resume() to continue the upload from where it stopped
Below is an example implementation of the iOS Upload SDK. You can customize the UI and components based on your app’s design.
Handling network throttling
Network throttling is the intentional slowing down of internet speeds by an Internet Service Provider (ISP) to manage network congestion.
FastPixUploadSDK is designed to handle network throttling efficiently, ensuring smooth video uploads even when network conditions are less than ideal. It automatically detects and adapts to bandwidth throttling, optimizing video upload speeds within the allowed data limits to ensure that the upload process continues without disruption.
Error handling
Proper error handling ensures the SDK gracefully handles failures and provides meaningful feedback.
Common error scenarios:
- Network failures
- Timeout errors
- Invalid data or server responses
- Permission issues
Implementation example:
Changelog
All notable changes to this project will be documented in this file.
[1.0.3]
Changed
- Code standardization updates applied across the SDK to align with best practices and strengthen overall stability.
[1.0.2]
Compatibility
- The SDK is now fully compatible with both old and new versions of Xcode (before and after Xcode 26) and Swift (Swift 5.x and Swift 6.x including Swift 6.3.2).
- No functionality has been changed. All fixes are only compatability ones, updates to ensure the SDK builds and runs correctly across all supported Xcode and Swift versions.
Fixed
- Fixed invalid
try (tuple)syntax inuploadFilethat caused a Swift 6.3.2 compiler crash (SILGen segfault) under Xcode 26. - Fixed
customizedChunkSizeincorrectly storing0whenchunkSizeKB: 0was passed. Bothniland0now correctly fall back to the SDK default (16384KB). - Fixed chunk size validation thresholds that were written in MB (
< 5,> 500) but compared against a value stored in KB, causing valid chunk sizes and the SDK default to always fail validation. - Fixed
FileHandleon iOS 13.0–13.3 silently returning emptyDatadue to a missing availability check. Legacyseek(toFileOffset:)andreadData(ofLength:)are now used as a fallback on iOS < 13.4. - Fixed missing
fileHandle.closeFile()fallback indeinitfor iOS < 13.0. - Fixed force-unwrap crash on
VideoChunkProcessor(fileURL:)returningnilwhen the file could not be opened. - Fixed force-unwrap crash on
currentChunkinrequestChunk. - Fixed
NotificationCenter.addObserverbeing called off the main thread whenuploadFileis invoked from a background thread.
Changed
- Replaced duplicated chunk-success logic in
submitHttpRequestwith a sharedhandleChunkSuccess()method. - All closures (
emit, upload task completion,asyncAfter) now captureselfweakly via[weak self]to prevent retain cycles. UploadEventassociated error values updated from bareErrortoany Errorfor Swift 5.7+ and Swift 6 compatibility.
Added
Sendableconformance added toUploadEvent,UploadsDelegate,UploadProgressDelegate, andUploadSDKErrorDelegatefor Swift 6 strict concurrency compliance.
Removed
- Removed unstable
() async throws -> Stringexistential type fromvalidateUserInputendpoint check, which is unsupported across Swift versions. - Removed unused variable
var response = 429and duplicateif let httpResponserebinding insidesubmitHttpRequest.
[1.0.1]
Changed
- Domain migration:
fastpix.io→fastpix.com- Direct Upload API endpoint updated from
https://api.fastpix.io/v1/on-demand/uploadtohttps://api.fastpix.com/v1/on-demand/upload. - README references for dashboard, documentation, and API links updated to use
.comdomains.
- Direct Upload API endpoint updated from
Note: Existing
.iodomains will continue functioning temporarily, but migration to.comendpoints is strongly recommended to avoid future disruptions.
[1.0.0]
Added
- Chunking: Files are automatically split into chunks (configurable, default size is 16MB/chunk).
- Pause and Resume: Allows temporarily pausing the upload and resuming after a while.
- Upload Lifecycle Callbacks: Track the entire upload process using callback functions to monitor upload lifecycle.
- Retry: Individual chunks are retried up to 5 times with exponential backoff to recover from temporary network failures.
- Error Handling: Comprehensive error management to notify users of issues during uploads.
- Customizability: Options to customize chunk size and retry attempts.
- Swift Package Manager Support: SDK is installable via SPM using the repo URL.
- Implemented support for Google Cloud Storage resumable uploads and chunked client uploads.
- Added retry mechanism with exponential backoff for GCS upload failures based on retryable status codes.
- Enabled support for user-provided signed URLs for resumable uploads with externally generated session URIs.
- Updated the API endpoint from
https://v1.fastpix.io/on-demand/uploadstohttps://api.fastpix.io/v1/on-demand/upload.