Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 
avatar of Ajjjjjjjj

Ajjjjjjjj

Ajjjjjjjj has asked 0 questions and find answers to 4 problems.

Stats

80
EtPoint
22
Vote count
0
questions
4
answers

About

/***************************/

{ // if ReachabilityManager.sharedInstance.isNetworkReachable() // { let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil)

    request             = URLRequest(url: URL(string: urlStr)!)
    request.httpMethod  = "POST"
    let boundary        = "Boundary-\(UUID().uuidString)"

    request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

    self.request.httpBody = createBody(parameters: parameters, boundary: boundary, data: imageData, jsonString: jsonString , mimeType:
        "image/jpg", filename: "")

    //        if let stringToken = UserDefaults.standard .value(forKey: AccessToken)
    //        {
    //            request.setValue(String.init(format: "Bearer %@", stringToken as! CVarArg) , forHTTPHeaderField: "Authorization")
    //        }
    //        do
    //        {
    let task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in

        let statusCode = (response as? HTTPURLResponse)?.statusCode
        if statusCode == successCode.success
        {
            if data != nil
            {
                completionHandler(data!,statusCode!)
            }
        }else if statusCode == successCode.createdSuccess{
            if data != nil
            {
                completionHandler(data!,statusCode!)
            }
        }
        else
        {
            if data != nil{
                completionHandler(data!,statusCode ?? 400)
            }
            print("Error is :\(String(describing: error))")
        }
    })
    task.resume()
    //        }
}