A sample project & library to use transloadit in your iOS apps
Objective-C Ruby
Pull request Compare This branch is 33 commits ahead, 1 commit behind transloadit:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
Screenshots
TransloaditAPI
.gitignore
License
Readme.md
TransloaditAPI.podspec

Readme.md

Transloadit iPhone SDK

The transloadit iPhone SDK contains the TransloaditRequest class and related dependencies. In addition, an example iPhone project is provided to help get you started.

This repository is a fork from the original transloadit API. This version however uses ARC, AFNetworking and Reachability. This also means this version of the API only works on iOS 6 and above.

Getting started

The provided example uses cocoapods. If you do not have cocoapods set up, follow their manual first.

Open a terminal and navigate to the Example directory and run: pod install

Then, open the TransloaditIphoneSdk.xcworkspace (not the .xcodeproj file). The first thing you should do is edit the Config.m file that comes with the project. You will need a transloadit account, as well as a template id.

Once you have set this up, you can start the example app and test some file uploads.

Using Transloadit in your own app

In order to use the API in your own app, you must first set up your project to use cocoapods if you haven't done so already. Next, add the TransloaditAPI as a dependency. Then add pod 'TransloaditAPI' as a dependency.

The TransloaditRequest class depends on additional libraries that are included through their cocoapod dependencies.

Example - UIImagePickerController

Assuming you have a UIImagePickerController callback, you can upload the selected file like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    TransloaditRequest *transload = [[TransloaditRequest alloc] initWithCredentials:@"your-key" secret:@"your-secret"];
    [transload setTemplateId:@"your-template-id"];
    [transload addPickedFile:info];
    [transload setNumberOfTimesToRetryOnTimeout:5];
    [transload setDelegate:self];
    [transload setUploadProgressDelegate:self];
    [transload startAsynchronous];
}

- (void)transloaditRequest:(TransloaditRequest *)request setProgress:(float)currentProgress andState:(TLUploadStatus)state
{
    NSLog(@"upload progress: %f", currentProgress);
}

- (void)transloaditRequestFinished:(TransloaditRequest *)transloadRequest
{
    NSString *assemblyId = [[transload response] objectForKey:@"assembly_id"];
    NSLog(@"assembly id: %@", assemblyId);
    [transload release];
}

- (void)transloaditRequestFailed:(TransloaditRequest *)transloadRequest error:(NSError*)error
{
    NSLog(@"request failed");
}

If you need to pass dynamic params instead of just a template id, you can tweak the example from above like this:

// [transload setTemplateId:@"your-template-id"];
NSMutableDictionary *steps = [[NSMutableDictionary alloc] init];
NSMutableDictionary *resizeStep = [[NSMutableDictionary alloc] init];
[resizeStep setObject:@"/image/resize" forKey:@"robot"];
[resizeStep setObject:[NSNumber numberWithInt:100] forKey:@"width"];
[resizeStep setObject:[NSNumber numberWithInt:100] forKey:@"height"];
[steps setObject:resizeStep forKey:@"resize"];
[[transload params] setObject:steps forKey:@"steps"];

TransloaditRequest API

@property(nonatomic, retain) NSMutableDictionary *params;

The params field with the instructions that will be send to transloadit.

@property(nonatomic, retain) NSDictionary *response;

The parsed response from transloadit.

- (id)initWithCredentials:(NSString *)key secret:(NSString *)secret;

Initializes a transloadit request with the given key and secret.

- (void)addRawFile:(NSString *)path withFileName:(NSString *)filename addContentType:(NSString *)type;

Takes a local file from the specified path and prepares it for uploading. This can be a video, image or audio file.

- (void)addRawData:(NSData *)data withFileName:(NSString *)filename addContentType:(NSString *)type;

Takes the data from as NSData object and prepares it for uploading. The can be a video, image or audio file.

- (void)addPickedFile:(NSDictionary *)info;

Takes a picked file and prepares it for uploading. This can either be a video or an image.

- (void)addPickedFile:(NSDictionary *)info forField:(NSString *)field;

Same as the above, but you can specify the form field name to be used for this upload.

- (void)setTemplateId:(NSString *)templateId;

Sets the TransloaditRequest.params.template_id property.

- (bool)hadError;

Returns true if transloadit returned an error code.

License

The Transloadit iPhone SDK is licensed under the MIT license. The dependencies have their own licenses.