Skip to main content

Upload Consultation Attachments

Upload Consultation Attachments Example

mediaIds can only be sent while creating the consultation. To attach files after that, upload them with uploadMedia and pass the returned ids to uploadConsultationAttachments.

ApiService.uploadConsultationAttachments(
id: Int,
mediaIds: [String],
completion: @escaping (ConsultationAttachments?, Data?, Error?) -> Void
)

id is the consultation id, and mediaIds are ids returned by uploadMedia

Send only the newly uploaded ids. Re-sending ids that are already attached is treated as a duplicate request

Check the example

import AltibbiTelehealth

func attachFile(data: Data, type: String, consultationId: Int) -> Void {
ApiService.uploadMedia(jsonFile: data, type: type, completion: {media, failure, error in
if let error = error {
print("Data Error: \(String(describing: error))")
} else if let failure = failure {
// Handle failure
} else if let mediaId = media?.id {
ApiService.uploadConsultationAttachments(id: consultationId, mediaIds: [mediaId], completion: {attachments, failure, error in
if let error = error {
print("Data Error: \(String(describing: error))")
} else if let failure = failure {
// Handle failure
} else {
print("Attached media: \(String(describing: attachments?.mediaIds))")
// Call getConsultationInfo to refresh the media list of the consultation
}
})
}
})
}

We have the struct ConsultationAttachments to decode the response

struct ConsultationAttachments {
var mediaIds: [String]?
}

Responses

Status 200

Success

{
"media_ids": ["3f1c7b2e-9d4a-4f2b-8c11-0a2d5e6f7a80"]
}

Status 401

UnauthorizedHttpException represents an Unauthorized HTTP exception with status code 401

{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials",
"code": "0",
"status": "401",
"type": "yii\\web\\UnauthorizedHttpException"
}

Status 403

Duplicate request

{
"name": "Forbidden",
"message": "duplicate request OR Current user cant access this page",
"code": "0",
"status": "403",
"type": "yii\\web\\ForbiddenHttpException"
}

Status 404

Consultation id invalid or consultation deleted

{
"name": "Not Found",
"message": "Object not found",
"code": "0",
"status": "404",
"type": "yii\\web\\NotFoundHttpException"
}

Status 422

Data Validation Failed

[
{
"field": "string",
"message": "string"
}
]