An iOS and macOS integration for Transloadit's file uploading and encoding service
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CommonCrypto
Example
Transloadit
.gitignore
.travis.yml
.travis.yml2
CHANGELOG.md
LICENSE
NSString+Utils.h
NSString+Utils.m
README.md
Transloadit.podspec
_Pods.xcodeproj

README.md

TransloaditKit SDK Build Status Version License Platform

An iOS and MacOS integration for Transloadit's file uploading and encoding service.

Intro

Transloadit is a service that helps you handle file uploads, resize, crop and watermark your images, make GIFs, transcode your videos, extract thumbnails, generate audio waveforms, and so much more. In short, Transloadit is the Swiss Army Knife for your files.

This is an iOS and MacOS SDK to make it easy to talk to the Transloadit REST API.

Install

Inside your podfile add,

pod 'Transloadit'

If there are no errors, you can start using the pod.

Usage

Import TransloaditKit

Objective-C

#import <TransloaditKit/Transloadit.h>

Swift

import Transloadit

Define your blocks

Objective-C

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

transloadit.uploadingResultBlock = ^(NSURL* fileURL){
// Use the upload url
NSLog(@"url: %@", fileURL);
};

transloadit.uploadingFailureBlock = ^(NSError* error){
// Handle the error
NSLog(@"error: %@", error);
};

transloadit.assemblyCreationResultBlock = ^(Assembly* assembly, NSDictionary* completionDictionary){
NSLog(@"Assembly creation success");
NSLog(@"%@", @"Invoking assembly.");
};

transloadit.assemblyCreationFailureBlock = ^(NSDictionary* completionDictionary){
NSLog(@"Assembly creation failed: %@", [completionDictionary debugDescription]);
};

transloadit.assemblyStatusBlock = ^(NSDictionary* completionDictionary){
NSLog(@"Assembly status: %@", [completionDictionary debugDescription]);
};

transloadit.assemblyResultBlock = ^(NSDictionary* completionDictionary){
NSLog(@"Assembly finished : %@", [completionDictionary debugDescription]);
};

transloadit.assemblyFailureBlock = ^(NSDictionary* completionDictionary){
NSLog(@"Assembly failed: %@", [completionDictionary debugDescription]);
};

Swift

self.transloadit.assemblyCreationResultBlock = { assembly, completionDictionary in
print("Assembly created!")
}
self.transloadit.assemblyCreationFailureBlock = { completionDictionary in
print("Assembly creation failed")
}

self.transloadit.assemblyResultBlock = { completionDictionary in
print("Assembly finished executing!")
}
self.transloadit.assemblyStatusBlock = { completionDictionary in
print("Assembly is executing!")
}

self.transloadit.assemblyFailureBlock = { completionDictionary in
print("Assembly failed executing!")
}

self.transloadit.uploadResultBlock = { url in
print("file uploaded!")
}
self.transloadit.uploadProgressBlock =  {bytesWritten, bytesTotal in
print("Assembly uploading!")
}
self.transloadit.uploadFailureBlock = { error in
print("Assembly failed uploading!")
}

self.transloadit.templateCreationResultBlock = { template, completionDictionary in
print("Template created!")
}

self.transloadit.templateCreationFailureBlock = { completionDictionary in
print("Template failed creating!")
}

Setup TransloaditKit

Objective-C

- (void)viewDidLoad {
[super viewDidLoad];
transloadit = [[Transloadit alloc] init];
}

Swift

// Simply setup a Transloadit object
let transloadit: Transloadit = Transloadit()

{PROJECT_NAME}.plist

<key>TRANSLOADIT_SECRET</key>
<string>SECRET_KEY_HERE</string>
<key>TRANSLOADIT_KEY</key>
<string>API_KEY_HERE</string>

Create an assembly and upload

Objective-C

NSMutableArray<Step *> *steps = [[NSMutableArray alloc] init];

//MARK: A Sample step
Step *step1 = [[Step alloc] initWithKey:@"encode"];
[step1 setValue:@"/image/resize" forOption:@"robot"];

// Add the step to the array
[steps addObject:step1];

//MARK: Create an assembly with steps
Assembly *TestAssemblyWithSteps = [[Assembly alloc] initWithSteps:steps andNumberOfFiles:1];
[TestAssemblyWithSteps addFile:fileUrl];
[TestAssemblyWithSteps setNotify_url:@""];

//MARK: Start The Assembly
[transloadit createAssembly:TestAssemblyWithSteps];


transloadit.assemblyCreationResultBlock = ^(Assembly* assembly, NSDictionary* completionDictionary){
[transloadit invokeAssembly:assembly];
}

Swift

override func viewDidLoad() {
super.viewDidLoad()
let AssemblyStepsArray: NSMutableArray = NSMutableArray()
let Step1 = Step (key: "encode")
Step1?.setValue("/image/resize", forOption: "robot")
TestAssembly = Assembly(steps: AssemblyStepsArray, andNumberOfFiles: 1)

self.TestAssembly?.addFile(fileURL)
self.transloadit.createAssembly(self.TestAssembly!)

self.transloadit.assemblyCreationResultBlock = { assembly, completionDictionary in
print("Assembly created!")
print("Assembly invoking!")
self.transloadit.invokeAssembly(assembly)
}
}

Example

Download the GitHub repo and open the example project examples/.

Contributing

We'd be happy to accept pull requests. If you plan on working on something big, please first drop us a line!

Building

The SDK is written in Objective-C for both iOS and MacOS.

Releasing

Releasing a new version to CocoaPods can be done via CocoaPods Trunk:

  • Bump the version inside the Transloadit.podspec
  • Save a release commit with the updated version in Git
  • Push a tag to Github
  • Publish to Cocoapods with Trunk

To Do

  • bridge TUSKit networking
  • websockets

Dependencies

  • TUSKit note TUSKit is installed along side Transloadit via CocoaPods

Authors

Contributions from:

License

MIT Licensed.