title: Error while uploading image to server with Swift
body: <p>Hi so here's the code I'm using to upload an image to our server via a link. </p>
  
  <pre><code>if (currentElementName == "uploadUrl") {
                  let returnUploadURL = string
  
                  var imageData = UIImagePNGRepresentation(pictureImage.image)
  
                  if imageData != nil{
                      var request = NSMutableURLRequest(URL: NSURL(string: returnUploadURL)!)
                      var session = NSURLSession.sharedSession()
                      println(request)
                      request.HTTPMethod = "POST"
  
                      var boundary = NSString(format: "---------------------------14737809831466499882746641449")
                      var contentType = NSString(format: "multipart/form-data; boundary=%@",boundary)
                      //  println("Content Type \(contentType)")
                      request.addValue(contentType, forHTTPHeaderField: "Content-Type")
  
                      var body = NSMutableData.alloc()
  
                      // Title
                      body.appendData(NSString(format: "\r\n--%@\r\n",boundary).dataUsingEncoding(NSUTF8StringEncoding)!)
                      body.appendData(NSString(format:"Content-Disposition: form-data; name=\"image.png\"\r\n\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)
                      body.appendData("Hello World".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!)
  
                      // Image
                      body.appendData(NSString(format: "\r\n--%@\r\n", boundary).dataUsingEncoding(NSUTF8StringEncoding)!)
                      body.appendData(NSString(format:"Content-Disposition: form-data; name=\"file\"; filename=\"image.png\"\\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)
                      body.appendData(NSString(format: "Content-Type: application/octet-stream\r\n\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)
                      body.appendData(imageData)
                      body.appendData(NSString(format: "\r\n--%@\r\n", boundary).dataUsingEncoding(NSUTF8StringEncoding)!)
  
                      request.HTTPBody = body
  
                      var returnData = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil)
                      var returnString = NSString(data: returnData!, encoding: NSUTF8StringEncoding)
  
                      println("returnString \(returnString)")
                  }
              }
  </code></pre>
  
  <p>For some reason I get this in the console and the app crashes. </p>
  
  <pre><code>&lt;NSMutableURLRequest: 0x17020d560&gt; { URL: http://oms/process.php?method=PQUEUE_INV_FILE }
  returnString Optional(Array
  (
      [file] =&gt; Array
          (
              [name] =&gt; r
              [type] =&gt; application/octet-stream
              [tmp_name] =&gt; /tmp/phpbAfzYN
              [error] =&gt; 0
              [size] =&gt; 17263726
          )
  
  )
  )
  &lt;NSMutableURLRequest: 0x174018130&gt; { URL: &amp; }
  fatal error: unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>First off, how is it giving it the filename "r"? And why am I getting this fatal error after the "&amp;" in the link? The link works this way. </p>
  
  <pre><code>"http://oms/process.php?method=PQUEUE_INV_FILE&amp;id=22405"
  </code></pre>