GithubHelp home page GithubHelp logo

kurtho / tuskit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tus/tuskit

0.0 1.0 0.0 714 KB

The tus client for iOS.

Home Page: https://tus.io/

License: MIT License

Ruby 1.17% Objective-C 98.83%

tuskit's Introduction

TUSKit

Protocol Version License Platform

An iOS client written in Objective-C for tus resumable upload protocol.

Pull Requests

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.

Installation

TUSKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TUSKit"

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first.

The Protocol

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.

Usage (1.4.2)


TUSSession

A NSURLSession that manages, creates, and reloads TUS uploads using a single NSURLSession and data store.

A simple session can be setup as follows:

by default, as of 1.4.2, a simple session has no request caching.

...
@property (strong, nonatomic) TUSSession *tusSession;
...
...
self.tusSession = [[TUSSession alloc] initWithEndpoint:[[NSURL alloc] initWithString:UPLOAD_ENDPOINT] dataStore:uploadStore allowsCellularAccess:YES];

Endpoint - An NSURL of your tus.io server.

dataStore - The TUSUploadStore you've created for your uploads.

allowsCellularAccess - Allow uploads over cell data.


However if you require more of an advanced setup and wish to use your own NSURLSessionConfiguration:

...
@property (strong, nonatomic) TUSSession *tusSession;
...
...
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
self.tusSession = [[TUSSession alloc] initWithEndpoint:[[NSURL alloc] initWithString:UPLOAD_ENDPOINT]  dataStore:uploadStore sessionConfiguration:sessionConfiguration];

Endpoint - An NSURL of your tus.io server.

dataStore - The TUSUploadStore you've created for your uploads.

sessionConfiguration - Your custom NSURLSessionConfiguration object.

TUSUploadStore

The data storage for uploads.

TUSUploadStore * uploadStore = [[TUSFileUploadStore alloc] initWithURL:[applicationSupportURL URLByAppendingPathComponent:FILE_NAME]];

URL - URL To Local File.

TUSResumableUpload

Easily add uploads to your data storage using the your TUSSession.

TUSResumableUpload *upload = [self.tusSession createUploadFromFile:fileUrl retry:3 headers:@{} metadata:@{}];

fileUrl - URL To Local File.

retry - The number of times you wish the upload to retry.

Headers - An NSDictionary of your custom headers for the upload.

Metadata - Any extra metadata you wanna attach to your upload

Resume - Starts and resumes upload.

[upload resume];

Stop - Stops upload.

[upload stop];

State - Get the current state of an upload.

[upload state];

Blocks

Progress Block

A block fired throughout the progress of your upload.

static TUSUploadProgressBlock progressBlock = ^(int64_t bytesWritten, int64_t bytesTotal) {
    // Update your progress bar here
    NSLog(@"progress: %llu / %llu", (unsigned long long)bytesWritten, (unsigned long long)bytesTotal);
};

Set it to your TUSResumableUpload object.

upload.progressBlock = progressBlock;

Failure Block

A block fired when your upload fails.

static TUSUploadFailureBlock failureBlock = ^(NSError* error){
    // Handle the error
    NSLog(@"error: %@", error);
};

Set it to your TUSResumableUpload object.

upload.failureBlock = failureBlock;

Result Block

A block fired when your upload is successful.

static TUSUploadResultBlock resultBlock = ^(NSURL* fileURL){
    // Use the upload url
    NSLog(@"url: %@", fileURL);
};

Set it to your TUSResumableUpload object.

upload.resultBlock = resultBlock;

Please refrence the Example Project for more usage examples

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.

Todo


License


TUSKit is available under the MIT license. See the LICENSE file for more info.

tuskit's People

Contributors

mmasterson avatar afh avatar felixge avatar michaelavila avatar alikaragoz avatar ruslanskorb avatar cjhenck avatar doggy avatar kvz avatar acconut avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.