O'Reilly logo

iOS and OS X Network Programming Cookbook by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required