A fresh look at using files on Kii Cloud

Objects vs. Files

Kii Cloud is born from a powerful mobile sync engine where files have always been a preferred type. For our SDKs, you will recognize these as KiiFile objects.

These KiiFile types are geared specifically for our sync infrastructure – and provide a slightly different feature set than many app developers may need. On the other side of things we have KiiObjects, which provide lots of flexibility for defining key/value attributes and also very efficient querying.

What would happen if we combined the best of both worlds?

KiiObject with file body

Kii Cloud has a great feature that has flown under the radar – which merges the KiiObject and KiiFile by allowing you to attach a data body to any KiiObject type. This means you can attach images, movies, audio or any kind of blob type to your existing KiiObjects! This will allow you to efficiently query, add unlimited key/value attributes and enjoy all the great features of KiiObject with your files.

How can I do this?

It’s pretty simple to add a body to your KiiObjects using our resumable upload functionality. Similarly, you can retrieve the body using the resumable download. Check out our bare-bones examples below, or head over to our comprehensive guides (iOS | Android) or documentation (iOS | Android).

Uploading a body to KiiObject in iOS

// reference or create an object
KiiObject *object = ...;

// Set arbitrary key-value pairs
[object setObject:@"MyVideo" forKey:@"myTitle"];
[object setObject:[NSNumber numberWithInt:10485760] forKey:@"myFileSize"];

// Create an uploader.
KiiUploader *uploader = [object uploader:myFilePath];

// Start uploading.
[uploader transferWithProgressBlock:^(id transferObject, NSError *error) {
    KiiRTransferInfo *info = [transferObject info];
    float completed = (float) [info completedSizeInBytes];
    float total = (float) [info totalSizeInBytes]
    NSLog(@"Progress : %f",  (float) completed / total);
} andCompletionBlock:^(id transferObject, NSError *error) {
    NSLog(@"File upload complete and object saved: %@", error);
}];

Uploading a body to KiiObject in Android

// reference or create an object
KiiObject object = ...;

// Set key-value pairs.
object.set("myTitle", "MyVideo");
object.set("myFileSize", 10485760);

// Create an uploader.
KiiUploader uploader = object.uploader(getApplicationContext(), myLocalFile);

// Start uploading
try {
  uploader.transfer(null);
} catch ... { }

Wrapping up

We hope you enjoy this feature within our SDKs – let us know your thoughts!

Happy coding 🙂

- Share -

Chris Beauchamp

More posts from

  • Kii IoT platform enables customers to create smart, connected solutions and services
  • Long track record of supporting customers like Docomo, Toshiba, Kyocera and many others
  • Strong ecosystem partners across the globe, consisting of carriers, device/sensor manufacturers, system integrators, network/infrastructure providers, chip vendors and solution developers
  • HQ in Tokyo, US HQ in Silicon Valley & offices in China, Taiwan, Hong Kong and Europe (UK, Spain, Germany)
  • www.kii.com