title: Uploading audio files using Alamofire
body: <p>I am trying to upload audio file to server using Alamofire from a table view UI.</p>
  
  <p>I am getting the app crashed I guess I am connecting my URL wrongly in multipartformdata line please help me how to set it right.</p>
  
  <pre><code>@IBAction func Upload(_ sender: Any) {
      let voiceData = try? Data(contentsOf: getDirectory())
      let params : [String:String] = []
  
      Alamofire.upload(
          multipartFormData: { (multipartForm) in
              multipartForm.append(voiceData!, withName: "voice", fileName: "file", mimeType: "audio/m4a")
              for (key, value) in params {
                  multipartForm.append(value.data(using: String.Encoding.utf8)!, withName: key)
              }
      },
          usingThreshold : SessionManager.multipartFormDataEncodingMemoryThreshold,
          to : "http://18.136.194.124/voupload.php",
          method: .post){ (result) in
  
              switch result {
  
  '''''''
      }
  
  func getDirectory() -&gt; URL
      {
          let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
          let documentDirectory = paths[0]
          return documentDirectory
      }
  
  
  @IBOutlet weak var mtable: UITableView!
  @IBOutlet weak var Butlabel: UIButton!
  var recordingSession:AVAudioSession!
  var audiorecorder:AVAudioRecorder!
  var audioPlayer:AVAudioPlayer!
  var numberOfrecords = 0
  
  
  @IBAction func RecordButton(_ sender: Any) {
  
      if audiorecorder == nil
      {
          numberOfrecords += 1
          let filename = getDirectory().appendingPathComponent("\(numberOfrecords).m4a")
  
  
          let settings = [AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 1200, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue]
  
          // VOXIT STARTS
          do
          {
              audiorecorder = try AVAudioRecorder(url: filename, settings: settings)
              audiorecorder.delegate = self
              audiorecorder.record()
  
              Butlabel.setTitle("Stop Recording", for: .normal)
          }
          catch{
              displayAlert(title: "Ups!", message: "Recording Failed")
          }
  
      }
      else
      {
          // STOP rec
      }
  }
  </code></pre>
  
  <p>if some one can explain me MultiDataForm code.
  Appreciate any help.</p>