0

Here is my code:

import UIKit
import Alamofire
import SwiftyJSON
import Alamofire_SwiftyJSON

class ViewController: UIViewController , UINavigationControllerDelegate , UIImagePickerControllerDelegate{

var Image = String()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func ChosePhoto(_ sender: Any) {
    let getimage = UIImagePickerController()
    getimage.delegate = self
    getimage.sourceType = UIImagePickerControllerSourceType.photoLibrary
    getimage.allowsEditing = false
    self.present(getimage, animated: true, completion: nil)
}


@IBAction func Uploading(_ sender: Any) {


    let requestURL = UU
    let param = [
        "S1" : "7f3a92a2-9c25-4b96-ba20-489c6412e36f",
        "S2" : "F/EogECr4Z1GwtVQANHq",
        "S3" : "EE0009BB-CF91-4ECB-AB5C-3F9BA6CA0A61" ,
        "Base64Image" : self.Image ,
        "FileId" : "bd535daf-21c6-4b4b-98d5-7042f7789aab",
        "Extension" : "jpeg" ,
        "CommentId" : "c1f57f35-1c81-4b4e-a1b5-18e14eb761e7"
    ]
    let header = [
        "Content-Type" : "application/json; charset=utf-8"
    ]

    Alamofire.request(requestURL, method: HTTPMethod.post, parameters: param, encoding: JSONEncoding.default, headers: header).responseString { response in
        switch response.result {
        case .success:
            let mess = response.result.value!
            print(mess)

        case .failure(let error):
            print(error)
        }
    }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
            let image = info[UIImagePickerControllerOriginalImage] as! UIImage?
            let data : Data = UIImageJPEGRepresentation(image!, 0.2)!
            let Ima = data.base64EncodedString(options: .endLineWithCarriageReturn)
            self.Image = Ima
            print(self.Image)
            self.dismiss(animated: true, completion: nil)
        }
    }

Here is the error:

SSL_ERROR_SYSCALL(5): operation failed externally to the library 2018-08-31 18:04:56.890342-0700 background[2690:63834] [BoringSSL] Function boringssl_session_errorlog: line 2868 [boringssl_session_write] SSL_ERROR_SYSCALL(5): operation failed externally to the library {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
Heba GH
  • 1
  • 2

1 Answers1

0

If you want to pass image in to string parameter you have to convert image into base64EncodedString

let imageData:NSData = UIImagePNGRepresentation(self.Image)!
let strBase64 = imageData.base64EncodedString(options: .lineLength64Characters)

And pass strBase64 into parameter value for Base64Image key in your case.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Pratik Sodha
  • 3,679
  • 2
  • 19
  • 38
  • im convert it as this : let data : Data = UIImageJPEGRepresentation(image!, 0.2)! let Ima = data.base64EncodedString(options: .endLineWithCarriageReturn) self.Image = Ima – Heba GH Sep 01 '18 at 07:00
  • @HebaGH change options of `endLineWithCarriageReturn ` to `lineLength64Characters ` – Pratik Sodha Sep 01 '18 at 07:12
  • return me the same error line 2868 [boringssl_session_write] SSL_ERROR_SYSCALL(5): operation failed externally to the library – Heba GH Sep 01 '18 at 07:15
  • {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""} – Heba GH Sep 01 '18 at 07:18
  • Ask to your backend developer for this - May be it's helpful - https://stackoverflow.com/questions/44139524/messagethere-was-an-error-processing-the-request-stacktrace-exception – Pratik Sodha Sep 01 '18 at 07:20
  • in backend its correct .. i think the error in alamofire or SwiftyJson becuase its work with other programmer – Heba GH Sep 01 '18 at 07:25