title: Swift Upload Video to Http server?
body: <p>I'm trying to upload video to my server.
  I select video from album but "fatal error: unexpectedly found nil while unwrapping an Optional value".</p>
  
  <p>Please find the below code for more information.</p>
  
  <pre><code>let videoURL: String = NSBundle.mainBundle().pathForResource("IMG_2859", ofType: "MOV")!
  // var videoData: NSData = NSData.dataWithContentsOfURL(NSURL.fileURLWithPath(videoURL))!
  print(videoURL)
  let data = NSData(contentsOfFile: videoURL)
  
  print(data)
  
  let session = NSURLSession.sharedSession()
  let request = NSMutableURLRequest()
  print(session)
  print(request)
  
  request.URL =  NSURL(string:  "uploadvideo/uploadtoserver?user_email=\(candit_email)")
  print(request.URL)
  
  request.HTTPMethod = "POST"
  
  let boundary = "------------------------8744f963ff229392"
  request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
  
  let postData = NSMutableData()
  postData.appendData("--\(boundary)\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
  
  print("Upload Video File1")
  postData.appendData("Content-Disposition: form-data; name=\"filedata\"; filename=\"MOV\"\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
   print("Upload Video File2")
  
  postData.appendData("Content-Type: video/x-msvideo\r\n\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
   print("Upload Video File3")
  postData.appendData(NSData(data: data!))
   print("Upload Video File4")
  postData.appendData("\r\n--\(boundary)--\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
  print("Upload Video File5")
  request.HTTPBody = postData
  
  print("Upload Video File6")
  
  print(request.HTTPBody)
  NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response: NSURLResponse?, data: NSData?, error: NSError?) -&gt; Void in
      let error: AutoreleasingUnsafeMutablePointer&lt;NSError?&gt; = nil
      do{
          if let jsonResult: NSDictionary! = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as? NSDictionary{
  
  
      }
      } catch let error as NSError {
      print(error.localizedDescription)
      }
  
  
  })
   }
  </code></pre>
  
  <p>I had referred this below two links but no use for me. </p>
  
  <p>1) <a href="https://stackoverflow.com/questions/27443838/imageor-video-posting-to-server-in-swift">Imageor-video-posting-to-server-in-swift</a><br>
  2) <a href="https://stackoverflow.com/questions/20088969/how-to-upload-video-to-server-from-iphone">how-to-upload-video-to-server-from-iphone</a></p>