title: Multipart form data upload with multiple images + parameters (Alamofire 5.2)
body: <p>I am trying to upload multiple images and parameters to the server using 'Alamofire 5.2)'
  This is what the server expects</p>
  <pre><code>[{&quot;key&quot;:&quot;media1&quot;,&quot;description&quot;:&quot;&quot;,&quot;type&quot;:&quot;file&quot;,&quot;value&quot;:[&quot;/C:/Users/x/x/x/x.jpg&quot;]},
  [{&quot;key&quot;:&quot;media2&quot;,&quot;description&quot;:&quot;&quot;,&quot;type&quot;:&quot;file&quot;,&quot;value&quot;:[&quot;/C:/Users/x/x/x/x.jpg&quot;]},
  [{&quot;key&quot;:&quot;media3&quot;,&quot;description&quot;:&quot;&quot;,&quot;type&quot;:&quot;file&quot;,&quot;value&quot;:[&quot;/C:/Users/x/x/x/x.jpg&quot;]},
  
  {&quot;key&quot;:&quot;model&quot;,&quot;value&quot;:&quot;{\&quot;emp_Id\&quot;: \&quot;6\&quot;,\&quot;device_Identifier\&quot;:\&quot;Device 01\&quot;,\&quot;timestamp\&quot;:\&quot;123\,”\description\”:\”description\&quot;,”handoverStatus”:”false”}&quot;,&quot;type&quot;:&quot;text&quot;}]
  
  //Please note the array part
  </code></pre>
  <p>This is how i add picked image to an image array</p>
  <pre><code>var dictImage : [UIImage]?
  
  if pickedImage.pngData() != nil
  {
    dictImage!.append(pickedImage)
  }
  
  </code></pre>
  <p>This is how im trying to call the alamofire upload</p>
  <pre><code>func xyz()
  {
          let param : [String: Any] = [
              &quot;emp_Id&quot; : &quot;&quot;,
              &quot;device_Identifier&quot; : &quot;&quot;,
              &quot;timestamp&quot; : &quot;&quot;,
              &quot;description&quot; : &quot;&quot;,
              &quot;handoverStatus&quot; : &quot;&quot;
          ]
      let urlString = URL(string: APIDetails.BaseUrl + &quot;api/123&quot;)!
      let url = (try? URLRequest(url: urlString, method: .post, headers: APIDetails.header))!
      AF.upload(multipartFormData: { (multipartData) in
          
          let img1 = arrImage![0]
          let img2 = arrImage![1]
          let img3 = arrImage![2]
  
          multipartData.append(img1.pngData(), withName:&quot;media1&quot;, fileName: &quot;\(Date().timeIntervalSince1970).jpg&quot;, mimeType: &quot;file&quot;)
          multipartData.append(img2.pngData(), withName:&quot;media2&quot;, fileName: &quot;\(Date().timeIntervalSince1970).jpg&quot;, mimeType: &quot;file&quot;)
          multipartData.append(img3.pngData(), withName:&quot;media3&quot;, fileName: &quot;\(Date().timeIntervalSince1970).jpg&quot;, mimeType: &quot;file&quot;)
              
          
          for (key, value) in param {
              multipartData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
          }
  
      }, with: url)
  }
  
  
  </code></pre>
  <p>How do i upload every image and its details as a dictionary?</p>
  <p>How do i add upload progress and result that shows if anything failed or not ?</p>
  <p>I tried with</p>
  <pre><code>
  }, with: url,encodingCompletion:{
          EncodingResult in
          switch EncodingResult{
          case .success(let upload, _, _):
              upload.responseJSON { response in
                  debugPrint(&quot;SUCCESS RESPONSE: \(response)&quot;)
              }
          case .failure(let encodingError):
  
              print(&quot;ERROR RESPONSE: \(encodingError)&quot;)
  
          }        })
  </code></pre>
  <p>But it gives error <code>Extra argument 'encodingCompletion' in call</code></p>
  <p>(This is my first time trying to upload multipart form data, the code/part of it was taken from another answer)</p>