title: iOS Swift uploading PDF file with Alamofire (Multipart)
body: <p>I'm currently developing an application using iOS 10 and Swift 3 and Alamofire 4</p>
  
  <p>The purpose of this application is to upload a PDF file generated previously.</p>
  
  <p>The PDF generation is working perfectly and the file is created.</p>
  
  <p>However the upload doesn’t work… 
  I received a success response but the file is not uploaded.</p>
  
  <p><strong>My server response</strong></p>
  
  <pre><code>Multi part Content-Type =&gt; multipart/form-data; boundary=alamofire.boundary.56958be35bdb49cb
  Multi part Content-Length =&gt; 293107
  Multi part Content-Boundary =&gt; alamofire.boundary.56958be35bdb49cb
   responses 
  SUCCESS: {
      uploadedFiles =     (
                  {
              details = " Key=Content-Disposition - values=[form-data; name=\"pdfDocuments\"] length=8";
              storedFileName = "/var/www/pdf/17/009/22/TMP104150531290406.tmp";
              type = PDF;
              uploadedDate = 1483999296701;
              uploadedFileName = UnknownFile;
          }
      );
  }
  end responses
  </code></pre>
  
  <p>I’m using multi-part to upload my file as Data as you can see <a href="https://github.com/Alamofire/Alamofire#uploading-data-to-a-server" rel="noreferrer">here</a> </p>
  
  <p>File url is fine. </p>
  
  <p>I have searched on SO but didn’t find any solution working… </p>
  
  <p>Here you can see my <strong>Controller</strong></p>
  
  <pre><code>Alamofire.upload(
              multipartFormData: {
                  multipartFormData in
  
                  if let urlString = urlBase2 {
                      let pdfData = try! Data(contentsOf: urlString.asURL())
                      var data : Data = pdfData
  
                      multipartFormData.append(data as Data, withName:"test.pdf", mimeType:"application/pdf")
                      for (key, value) in body {
                          multipartFormData.append(((value as? String)?.data(using: .utf8))!, withName: key)
                      }
  
                      print("Multi part Content -Type")
                      print(multipartFormData.contentType)
                      print("Multi part FIN ")
                      print("Multi part Content-Length")
                      print(multipartFormData.contentLength)
                      print("Multi part Content-Boundary")
                      print(multipartFormData.boundary)
                  }
          },
              to: url,
              method: .post,
              headers: header,
              encodingCompletion: { encodingResult in
  
                  switch encodingResult {
  
                  case .success(let upload, _, _):
                      upload.responseJSON { response in
                          print(" responses ")
                          print(response)
                          print("end responses")
  
                          onCompletion(true, "Something bad happen...", 200)
  
                      }
                  case .failure(let encodingError):
                      print(encodingError)
                      onCompletion(false, "Something bad happen...", 200)
                  }
          })
  </code></pre>
  
  <p>Thanks in advance for the help.</p>
  
  <p>Regards</p>