title: Uploading image to Parse.com with AFNetworking causing corrupt image
body: <p>I am trying to upload images to Parse.com using AFNetworking 2.0.
  When I download the image which has been stored on 'Parse', then the resulting file is corrupt.</p>
  
  <p>By doing a diff I see that the following data has been appended to the beginning:</p>
  
  <p><img src="https://i.stack.imgur.com/1vB3T.jpg" alt="enter image description here"></p>
  
  <p>There is also appended 'boundry' data at the end of the file.</p>
  
  <p>What am I doing wrong? Mime type?</p>
  
  <p>I send the same file using 'curl' and everything is ok. </p>
  
  <p>This is the code I use for sending:</p>
  
  <pre><code>AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  [manager setResponseSerializer:[AFJSONResponseSerializer serializer]];
  
  [manager.requestSerializer setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
  
  [headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
      [manager.requestSerializer setValue:value forHTTPHeaderField:key];
  }];
  
  [manager POST:@"https://api.parse.com/1/files/imagefile.jpg"
     parameters:nil constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData)
        {
            NSData *imgData = UIImageJPEGRepresentation(image, 1.0f);
  
            [formData appendPartWithFileData:imgData
                                        name:@"imagefile"
                                    fileName:@"imagefile.jpg"
                                    mimeType:@"image/jpeg"];
        }
        success:^(AFHTTPRequestOperation *operation, id responseObject) {
            success(operation, responseObject);
        }
        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            failure(operation, error);
        }
   ];
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The following code works as expected (not multi-part, so clearly this is the problematic area):</p>
  
  <pre><code>NSMutableString *urlString = [NSMutableString string];
  [urlString appendString:@"https://api.parse.com/1/"];
  [urlString appendFormat:@"files/imagefile.jpg"];
  
  NSURL *url = [NSURL URLWithString:urlString];
  
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
  [request setHTTPMethod:@"POST"];
  [request addValue:@"***********" forHTTPHeaderField:@"X-Parse-Application-Id"];
  [request addValue:@"***********" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
  [request addValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
  [request setHTTPBody:UIImageJPEGRepresentation(image, 0.3f)];
  
  NSURLResponse *response = nil;
  NSError *error = nil;
  
  [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  
  NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
  NSString *fileUrl = [httpResponse allHeaderFields][@"Location"];
  </code></pre>