ios – Server response throwing Unable to course of whereas importing doc/Picture to server in Swift


I’m attempting to importing doc to server. In Motion sheet, Consumer can select Picture from gallery to Doc to add.

So, I’m taking both photograph or doc and changing it into Information.
After that I’m sending that knowledge to server together with two parameters (keys, values) with multipart.

However, Sadly I get error like Unable to course of from server, However identical factor working in Android area.

Right here is my code:

    func uploadDocument(documentId:Int, knowledge: Information, filePath: String, categoryType: String, completion: @escaping uploadDocumentClosure) {
        
        let url = "https://somedomain.com/uploadDocument"
        
        let requestURL = URL(string: url)!
        let request = NSMutableURLRequest(url: requestURL)
        request.cachePolicy = .reloadIgnoringLocalCacheData
        request.httpShouldHandleCookies = false
        request.timeoutInterval = 30
        request.httpMethod = "POST"

        let filename = "avatar.png"
        // generate boundary string utilizing a singular per-app string
        let boundary = UUID().uuidString

        let docData = knowledge
        
             let idStr = "id"
            let docTypeStr = "documentType"
            let file = "file"
        
        var knowledge = Information()

        request.setValue("multipart/form-data; boundary=(boundary)", forHTTPHeaderField: "Content material-Sort")
        request.addValue("Bearer (accessToken ?? "")", forHTTPHeaderField: "Authorization")
        request.httpMethod = "POST"
        
        knowledge.append("rn--(boundary)rn".knowledge(utilizing: .utf8)!)

        knowledge.append("Content material-Disposition: form-data; title="(docTypeStr)"rnrn".knowledge(utilizing: .utf8)!)
        knowledge.append("(categoryType)".knowledge(utilizing: .utf8)!)

        knowledge.append("rn--(boundary)rn".knowledge(utilizing: .utf8)!)
        knowledge.append("Content material-Disposition: form-data; title="(file)"rnrn".knowledge(utilizing: .utf8)!)

        // Add the picture knowledge to the uncooked http request knowledge
        knowledge.append("rn--(boundary)rn".knowledge(utilizing: .utf8)!)
//        knowledge.append("Content material-Disposition: form-data; title="file"; filename="(filename)"rn".knowledge(utilizing: .utf8)!)
//
        if let dataa = "Content material-Disposition: form-data; title="(filename)"; filename="picture.jpg"rn".knowledge(utilizing: .utf8) {
            knowledge.append(dataa)
        }

        knowledge.append("Content material-Sort: picture/pngrnrn".knowledge(utilizing: .utf8)!)
        knowledge.append(docData)

        knowledge.append("rn--(boundary)--rn".knowledge(utilizing: .utf8)!)
        
        self.serviceManager.async(request: request as URLRequest) { (innerClosure) in
            do {
                let response = strive innerClosure()
                guard let json = response.jsonObject else {
                    completion({ throw JSONErrorType.parsingError })
                    return
                }
                let jsonData = strive JSONSerialization.knowledge(withJSONObject: json, choices: [])
                let responseModel = strive JSONDecoder().decode(EditProfilePhotoUploadResponse.self, from: jsonData)
                completion({ return responseModel })
            } catch {
                completion({ throw error })
            }
        }
    }

And the sever response is beneath

{
  "standing" : "E",
  "message" : "Unable to course of.",
  "knowledge" : null,
  "messageList" : null
}

With standing code 400 unhealthy request.sw

Any recommendations?