title: iOS: Alamofire multipart image submit
body: <p>I'm trying to submit an image with some other values to an "Article" object, which works except when I'm adding an image then I will get the following error: </p>
  
  <blockquote>
    <p>ArgumentError (invalid byte sequence in UTF-8)</p>
  </blockquote>
  
  <p>This is my function for submitting a new object:</p>
  
  <pre><code>func submitArticle() {
      let description = fullDescription.text!
      let categoriesId = categoriesArray[self.categoryPicked]["id"] as! Int
      let locationId = locationsArray[self.locationPicked]["id"] as! Int
      let userId = User.sharedInstance.userId
  
      Alamofire.upload(.POST, submitLink, multipartFormData: { multipartFormData in
          multipartFormData.appendBodyPart(data: self.name.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[name]")
          multipartFormData.appendBodyPart(data: description.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[description]")
          multipartFormData.appendBodyPart(data: self.sDescription.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[subdescription]")
          multipartFormData.appendBodyPart(data: "\(categoriesId)".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[category_id]")
          multipartFormData.appendBodyPart(data: "\(locationId)".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[location_id]")
          multipartFormData.appendBodyPart(data: "\(self.lng)".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[Xcoordinate]")
          multipartFormData.appendBodyPart(data: "\(self.lat)".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[Ycoordinate]")
          multipartFormData.appendBodyPart(data: "\(userId)".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"article[user_id]")
          for var i = 0; i &lt; self.photoArray.count; i++ {
              let imageData = UIImageJPEGRepresentation(self.photoArray[i], 1)
              multipartFormData.appendBodyPart(data: "image_iOS_device".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name: "article[article_images_attributes][][title]")
              multipartFormData.appendBodyPart(data: imageData!, name: "article[article_images_attributes][][image]", mimeType: "image/jpeg")
          }
      },
      encodingCompletion: { encodingResult in
          switch encodingResult {
          case .Success(let upload, _, _):
              upload.responseJSON { response in
                  debugPrint(response)
              }
          case .Failure(let encodingError):
              print(encodingError)
          }
      })
  }
  </code></pre>
  
  <p>So my question is how do I correctly add the image to this multipart form?</p>