An iOS client written in Objective-C
for tus resumable upload protocol.
TUSKit 1.3.1
is not yet out on Cocoapods, but can be installed by downloading the repo and including the /Pod/Classes
folder into your project.
This version has improved upload storage and background uploads. Sparse documentation can be found in the example. After the pod is released full documentation will follow.
Pull requests are always welcome! However, please submit a PR to the development
branch in order to keep the master
branch match up with the TUSKit
pod at all times.
TUSKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TUSKit"
To run the example project, clone the repo, and run pod install
from the Example directory first.
You'll need a tus.io friendly server before using TUSKit or any other tus client. You can find a list of tus implementations here.
Each file you upload must be in the form of a TUSAssetData
object. Create an TUSAssetData
object by initializing with an ALAsset
object.
TUSAssetData *uploadData = [[TUSAssetData alloc] initWithAsset:asset];
An upload can be created by initializing a TUSResumableUpload
object. If your server requires specific headers for communication such as authentication, you may pass these headers on initialization.
TUSResumableUpload *upload = [[TUSResumableUpload alloc] initWithURL:UPLOAD_ENDPOINT data:uploadData fingerprint:fingerprint uploadHeaders:headers fileName:@"video.mp4"];
URL - The URL to your tus.io server.
data - The TUSAssetData
object you are uploading.
fingerprint - The absoulute path to the asset.
uploadHeaders - An NSDictionary
of your custom headers for the upload.
filename - The filename...
To start the upload process, run the start
method on your TUSResumableUpload
object.
[upload start];
A block to track progess on your upload. Here you can update your progress bar, print to the log, etc.
upload.progressBlock = ^(NSInteger bytesWritten, NSInteger bytesTotal){
NSLog(@"progress: %d / %d", bytesWritten, bytesTotal);
};
A block fired after a successful upload, returning the URL to your file on the server. Handle your success here!
upload.resultBlock = ^(NSURL* fileURL){
NSLog(@"url: %@", fileURL);
};
A block fired after a failed upload, returning the error. Handle your failure here!
upload.failureBlock = ^(NSError* error){
NSLog(@"error: %@", error);
};
Background Uploads
About tus.io:
Users want to share more and more photos and videos. But mobile networks are fragile. Platform APIs are a mess. Every project builds its own file uploader. A thousand one week projects that barely work, when all we need is one real project, done right.
We are going to do this right. We will solve reliable file uploads for once and for all. A new open protocol for resumable uploads built on HTTP. Simple, cheap, reusable stacks for clients and servers. Any language, any platform, any network.
TUSKit is a ready to use tus client for iOS.
TUSKit is available under the MIT license. See the LICENSE file for more info.