title: ios multipart image upload, uploaded file is corrupted
body: <p>I am making a multipart POST request to server and everything works fine, but the jpeg I'm uploading doesn't have the file extension and can't be opened (the file size is the same as orginal). I've tried this on tho different servers and the same error occured, so I'm assuming it's the issue of my app code.</p>
  
  <pre><code>let boundary = generateBoundaryString()
      let request = NSMutableURLRequest(URL: Urls.sendFileURL)
      request.HTTPMethod = "POST"
      request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
  
      let body = NSMutableData()
  
      for (key, value) in params {
          body.appendString("--\(boundary)\r\n")
          body.appendString("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n")
          body.appendString("\(value)\r\n")
      }
  
  
      let imageData: NSData = UIImageJPEGRepresentation(photo, 0.8)
  
      body.appendString("--\(boundary)\r\n")
      body.appendString("Content-Disposition: form-data; name=\"iosUpload\"; filename=\"iosUpload.jpg\"\r\n\r\n")
      body.appendString("Content-Type: image/jpeg\r\n\r\n")
      body.appendData(imageData)
      body.appendString("\r\n")
      body.appendString("--\(boundary)\r\n")
  
      request.HTTPBody = body
  </code></pre>
  
  <p>I've tried my POST using posttestserver.com
   <a href="http://posttestserver.com/data/2015/05/12/momentum/07.44.46618948283" rel="nofollow">this is the result</a></p>