postRequest.addMultipartData(imageData, withName: "media_id", type: "POST media/upload", filename: "image.jpg")
That looks like it’s wrong. The media_id is expected to be an ID of a previously successfully uploaded image using the POST media/upload endpoint.
That means that you first need to do a POST to the media/upload endpoint using multipart/form-data encoding. If this is successful, you will get a response like the following:
{
"media_id": 553639437322563584,
"media_id_string": "553639437322563584",
"size": 998865,
"image": {
"w": 2234,
"h": 1873,
"image_type": "image/jpeg"
}
}
You need to use that media_id (or media_id_str if your JSON parser can’t handle large integers) and use it for the media_id value, when tweeting with the statuses/update endpoint. Note that this endpoint should not be multipart/form-data encoded.