title: Image uploading with parameters using Alamofire in Swift
body: <p>I am using Alamofire for my data post to the server. I ahve an image which I want to upload to server in Data form with some other parameters. In Alamofire, I am using multipartFormData method to post all the parameters and image. Server needs data to be in JSON format with parameters which is shown below:</p>
  
  <pre><code> {"product_name": "almondsfdsfsdf",
   "product_price": "400",
   "product_img": image.jpg}
  </code></pre>
  
  <p>I am trying but it gives me a failure in response. Here is my code of what I am doing in swift with alamofire:</p>
  
  <pre><code>let productName = itemNameTF.text!
  let productPrice = itemPriceTF.text!
  let productImage:UIImage = itemImage.image!
  let url = "URL"
  let parameter = ["product_name": productName, "product_price": productPrice]
  let headers : HTTPHeaders = ["Content-Type": "application/json","Authorization" : "Token abcd"]
  Alamofire.upload(multipartFormData: {
              multipartFormData in
              if let imageData = UIImageJPEGRepresentation(productImage, 0.5){
                  multipartFormData.append(imageData, withName: "image", fileName: "file.png", mimeType: "image/png")
              }
  
              for (key,value) in parameter {
                  multipartFormData.append(value.data(using: .utf8)!, withName: key)
              }
          }, to: url,method: .post, headers: headers, encodingCompletion: { encodingResult in
              switch encodingResult {
              case .success(let upload,_,_):
                  upload.responseJSON { response in
  
                      print(response.request)
                      print(response.response)
                      print(response.result)
                      print(response.data)
                  }
                  break
              case .failure(let encodingError):
                  print("error: \(encodingError)")
                  break
              }
          })
  </code></pre>
  
  <p>My server accept image in BLOB data. If anyone could help me. Thank you!</p>