0

I'm tyring to upload an image that is selected by the user either through the gallery or by taking a photo but I am getting SSL_ERROR_SYSCALL(5).

Full error: boringssl_session_errorlog(236) [C1.1:2][0x105a04e20] [boringssl_session_write] SSL_ERROR_SYSCALL(5): operation failed externally to the library

I have tried a number of different methods with parameters and no parameters. I know the upload script is working as I can send a request to the endpoint using Postman and the file uploads correctly.

let headers: HTTPHeaders = [
        "Content-type": "multipart/form-data"
    ]

    let imageData = UIImagePNGRepresentation(imgPostHero.image!)

    Alamofire.upload(multipartFormData:{ multipartFormData in
        multipartFormData.append(imageData!, withName: "image", fileName: "uploaded_image.png", mimeType: "image/png")},
        usingThreshold: UInt64.init(),
        to: "https://url_to_upload_script",
        method: .post,
        headers: headers,
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                upload.responseJSON { response in
                    print(response)
                }
            case .failure(let encodingError):
                print(encodingError)
            }
    })
user1020496
  • 99
  • 1
  • 9

1 Answers1

0

It might happen because you are connecting through TLS (https) and the server you are connecting to has untrusted or invalid SSL public certificate. The reason might be e.g. it has expired, issued to wrong url or is self-signed.

The best practice is to implement proper ServerTrustPolicy. On a development stage it might be enough to trust any url, but when it comes to production, the SSL verification is a must.

Look at the link: Alamofire with a self-signed certificate / ServerTrustPolicy

tomieq
  • 29
  • 1
  • 4