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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.