The transloadit iPhone SDK contains a sample iPhone project along with a
TransloaditRequest
class that you can use in your own project.
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 app and test some file uploads.
In order to use transloadit in your own app, you need to add the following files to your project:
Classes/Transloadit/TransloaditRequest.h
Classes/Transloadit/TransloaditRequest.m
The TransloaditRequest
class depends on two additional libraries that you
need to install separately:
- json-framework (New BSD License)
- ASIHttpRequest (BSD License)
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"];
The params
field with the instructions that will be send to transloadit.
The parsed response from transloadit.
Initializes a transloadit request with the given key
and secret
.
Takes a picked file and prepares it for uploading. This can either be a video or an image.
Same as the above, but you can specify the form field name to be used for this upload.
Sets the TransloaditRequest.params.template_id
property.
Returns true
if transloadit returned an error code.
The Transloadit iPhone SDK is licensed under the MIT license. The dependencies have their own licenses.