Uploading a file using MKNetworkKit

In this recipe we will show you how to use MKNetworkKit to upload a file to a server by attaching it as part of a multipart form POST request. Since all of MKNetworkKit's functionality is encapsulated within MKNetworkEngine and MKNetworkOperation, we need to create an engine for our upload.

We will be using the addData:forKey:mimeType:filename: method to upload an image. The MKNetworkOperation class also has an addFile:forKey:mimeType:filename: method that allows us to attach a file directly.

Getting ready

This recipe is compatible with both iOS and OS X. We need to download the framework from https://github.com/MugunthKumar/MKNetworkKit and add it to our project. We also need to add the following four frameworks: ...

Get iOS and OS X Network Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.