title: Binary Image POST - iOS
body: <p>I have an app which makes a OAuth 1.0a POST request to the Tumblr API. I have been following their documentation for how to upload a photo and although I have set the parameters, it doesn't work.</p>
  
  <p>The Tumblr API Documentation states that you need these in your parameters:</p>
  
  <p>source - (string) - The photo source URL</p>
  
  <p>data - (Array URL-encoded binary contents) - One or more image files (submit multiple times to create a slide show)</p>
  
  <p>So I have setup my POST request as follows but I can't seem to get it to work. Here is my code:</p>
  
  <pre><code>// Tumblr POST Request.
  NSString *inputted_text = [inputted_text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  
  NSData* imageData = UIImagePNGRepresentation(image_selected);
  
  NSString *path = [NSString stringWithFormat:TUMBL_POST, tumblr_profilename];
  
  NSDictionary *parameters;
  
  if (media_post_check == 0) {
              // Text post.
  
              parameters = @{@"api_key" : TUMBL_CONSUMER_KEY,
                             @"type" : @"text",
                             @"body" : inputted_text};
          }
  
          else if (media_post_check == 1) {
              // Photo post.
  
              NSData *data_64 = [imageData base64EncodedDataWithOptions:0];
  
              parameters = @{@"api_key" : TUMBL_CONSUMER_KEY,
                             @"type" : @"photo",
                             @"caption" : inputted_text,
                             @"data" : @[data_64]};
          }
  
          else if (media_post_check == 2) {
              // Video post.
  
              parameters = @{@"api_key" : TUMBL_CONSUMER_KEY,
                             @"type" : @"link",
                             @"title" : @"Hello there",
                             @"url" : pub_video_url};
          }
  
          // Build authorized request based on path, parameters, tokens, timestamp etc.
          NSURLRequest *preparedRequest = [OAuth1Controller preparedRequestForPath:path parameters:parameters HTTPmethod:@"POST" oauthToken:token_tumblr oauthSecret:token_secret_tumblr];
  
          NSData *urlData;
          NSURLResponse *response;
          NSError *error;
  
          // Make synchronous request.
          urlData = [NSURLConnection sendSynchronousRequest:preparedRequest returningResponse:&amp;response error:&amp;error];
          NSLog(@"%@", response);
  </code></pre>
  
  <p>Do I need to send the image data or a link to it? What am I doing wrong?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I am now getting this error response:</p>
  
  <pre><code>Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x112a50a90 {NSUnderlyingError=0x10d6e1370 "The network connection was lost.", NSErrorFailingURLStringKey=http://api.tumblr.com/v2/blog/supertecnoboff.tumblr.com/post?api_key=wPqSZcRrJM4Rxu9oRECjcAzcvkq8EPwYq2LN98W13U39tDRPbZ&amp;caption=Test%2520star&amp;data%5B%5D=%3C6956424f%20527730206a........data...........14d6a%2048686871%204876672f%202f394763%2045684a68%205a574d41%2041414141%205355564f%20524b3543%205949493d%3E&amp;type=photo, NSLocalizedDescription=The network connection was lost.}
  </code></pre>
  
  <p>Thanks for your time, Dan.</p>