title: AFNetworking: Send image from file
body: <p>I am trying to send a multi-part post request which includes an image. The following code works fine:</p>
  
  <pre><code> manager.POST( apiUrl + "/location/add",
          parameters: parameters,
          constructingBodyWithBlock: { (formData : AFMultipartFormData!) -&gt; Void in
            //  formData.appendPartWithFileURL(NSURL(string: location.imagePath!), name: "image", error: nil)},
              formData.appendPartWithFileData(img, name: imgParam, fileName: "randomimagename.jpg", mimeType: "image/jpeg")},
          success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
              println("JSON: " + responseObject.description)
              var dict = responseObject as NSDictionary
              let json = JSONValue(dict)
  
              var message = ""
              if let msg = json["message"].string {message = msg}
              var success = false
              if let s = json["success"].bool {
                  callback(success: success, msg: message)
              }
          },
          failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
              println("Error: " + error.localizedDescription)
              var apiError = ApiError()
              apiError.noConnection = true
              errorCallback(apiError: apiError)
      })
  </code></pre>
  
  <p>I want to use <code>appendPartWithFileURL</code> instead of <code>appendPartWithFileData</code>. If I replace the 5th line wiht the line which is commented out in the code above, I get the following compiler error:</p>
  
  <pre><code>Extra argument 'constructingBodyWithBlock' in call
  </code></pre>
  
  <p>Does anybody know how to resolve this?</p>
  
  <hr>
  
  <p><strong>edit:</strong> Found a (very, very, very strange) solution. Replace the line</p>
  
  <pre><code>formData.appendPartWithFileURL(NSURL(string: location.imagePath!), name: "image", error: nil)},
  </code></pre>
  
  <p>with </p>
  
  <pre><code>var temp = formData.appendPartWithFileURL(NSURL(string: location.imagePath!), name: "image", error: nil)},
  </code></pre>
  
  <p>I didn't change anything beside adding <code>var temp =</code>. I have no idea why this is working, but it does. Seems to be a strange bug.</p>