title: How can I upload image with JSON parameters with Alamofire in Swift?
body: <p>I need to upload an image to the server endpoint where the structure has to be as following:</p>
  <pre><code>    {
          &quot;name&quot;: &quot;&quot;,
          &quot;description&quot;: &quot;&quot;,
          &quot;photo&quot;: imageFile
      }
  </code></pre>
  <p>How can I send such a request using Alamofire?</p>
  <p>I tried this but the result is error with error message <code>Invalid type in JSON write (NSConcreteData)</code>
  This is my code :</p>
  <pre><code>    let imageData = UIImagePNGRepresentation(image)
      let base64String = imageData!.base64EncodedDataWithOptions([])
      
      let parameters = [
          &quot;name&quot;: &quot;name&quot;,
          &quot;description&quot;: &quot;desc&quot;,
          &quot;photo&quot;: base64String
      ]
      
      let credentialData = &quot;\(id):\(secret)&quot;.dataUsingEncoding(NSUTF8StringEncoding)!
      let base64Credentials = credentialData.base64EncodedStringWithOptions([])
      let headers = [&quot;Authorization&quot;: &quot;Basic \(base64Credentials)&quot;]
  
      Alamofire.request(.POST, &quot;&quot;, parameters: parameters, encoding: .JSON, headers: headers).responseJSON { (response) -&gt; Void in
          print(response)
      }
  </code></pre>
  <p>And I followed this <a href="https://stackoverflow.com/a/32088875">code</a></p>
  <p>If there is another way to do please advice, thanks.</p>