TransloaditKit
An iOS & macOS Integration for Transloadit's file uploading and encoding service
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
The library can be downloaded manually from this repo, or installed with your favorite package managment software
CocoaPods:
pod 'transloadit'
Carthage:
Swift Package Manager:
Install Troubleshooting
CocoaPods
If during install you receive an error resembling:
[!] CocoaPods could not find compatible versions for pod "TUSKit":
In Podfile:
Transloadit (from `../`) was resolved to 2.0.5.alpha, which depends on
TUSKit (~> 2.1.5.alpha)
None of your spec sources contain a spec satisfying the dependency: `TUSKit (~> 2.1.5.alpha)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Please follow instructions and run pod repo update
Setup
All interactions with the SDK begin with the import Transloadit
Before utilizing, you'll need to configure your TransloaditKit library with desired config.
Implement
You can implement directly in your AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
var config = TransloaditConfig(withKey: "", andSecret: "")
Transloadit.setup(with: config)
return true
}
or add your keys to Transloadit.plist
in your root directory and enter a default config
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
var config = TransloaditConfig()
Transloadit.setup(with: config)
return true
}
Transloadit.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>key</key>
<string>PUT_KEY_HERE</string>
<key>secret</key>
<string>PUT_SECRET_HERE</string>
</dict>
</plist>
Other Configs
Logging
config.logLevel = .All
URLSession
Delegate
Be sure to set the delegate in order to receive proper callbacks from the library
Transloadit.shared.delegate = self
Usage
Create an Assembly
To create an Assembly, you use the newAssembly
method.
// Create the assembly
let assembly: Assembly = Transloadit.shared.newAssembly()
//Create the steps
var resizeSteps: [String: Any] = [:]
newSteps["robot"] = "/image/resize"
newSteps["width"] = 75
//Add the steps
assembly.addStep(name: "resize", options: resizeSteps)
//Add the file
assembly.addFile(withPathURL: imageURL as! URL)
//Create and run the assembly
assembly.save()
Example
Download the GitHub repo and open the Example/
folder.