Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A sample project & library to use transloadit in your iPhone apps

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 Example Final project cleanup March 24, 2012
Octocat-spinner-32 Screenshots Initial commit July 18, 2010
Octocat-spinner-32 TransloaditSDK
Octocat-spinner-32 .gitignore Updated gitignore (xcode 4) March 18, 2012
Octocat-spinner-32 License
Octocat-spinner-32 Readme.md add deprecation notice March 26, 2014
Readme.md

This SDK is deprecated. Please checkout our new iOS SDK.

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.

Getting started

Within the Example directory, open the TransloaditIphoneSdk.xcodeproj in XCode 4+. 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 SDK in your own app, simply drag the TransloaditSDK directory into your XCode project.

The TransloaditRequest class depends on two additional libraries that are included:

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)setProgress:(float)currentProgress
{
    NSLog(@"upload progress: %f", currentProgress);
}

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

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"];

Example - Audio from file path

- (void)transloadAudioFile
{
    NSString *myPath = @"/someLocalFile.wav";

    TransloaditRequest *transload = [[TransloaditRequest alloc] initWithCredentials:@"your-key" secret:@"your-secret"];
    [transload setTemplateId:@"your-template-id"];
    [transload addRawFile:myPath withFileName:@"myfile.wav" addContentType:@"audio/wav"];
    [transload setNumberOfTimesToRetryOnTimeout:5];
    [transload startAsynchronous];
}

Example - Image from NSData

- (void)transloadImageData
{
    NSData *myData = UIImagePNGRepresentation([UIImage imageNamed:@"myImageFile.png"]);

    TransloaditRequest *transload = [[TransloaditRequest alloc] initWithCredentials:@"your-key" secret:@"your-secret"];
    [transload setTemplateId:@"your-template-id"];
    [transload addRawData:myData withFileName:@"myfile.png" addContentType:@"image/png"];
    [transload setNumberOfTimesToRetryOnTimeout:5];
    [transload startAsynchronous];
}

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.

Something went wrong with that request. Please try again.