【问题标题】:Alamofire.upload operation failed externally to libraryAlamofire.upload 操作在库外部失败
【发布时间】:2019-06-11 04:51:32
【问题描述】:

我很想上传用户通过图库或拍照选择的图像,但我收到 SSL_ERROR_SYSCALL(5)。

完全错误:boringssl_session_errorlog(236) [C1.1:2][0x105a04e20] [boringssl_session_write] SSL_ERROR_SYSCALL(5):库外部操作失败

我尝试了许多带参数和不带参数的不同方法。我知道上传脚本正在工作,因为我可以使用 Postman 向端点发送请求并且文件正确上传。

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)
            }
    })

【问题讨论】:

    标签: swift3


    【解决方案1】:

    这可能是因为您通过 TLS (https) 进行连接,并且您要连接的服务器具有不受信任或无效的 SSL 公共证书。原因可能是例如它已过期、发给错误的 url 或自签名。

    最佳做法是实施适当的 ServerTrustPolicy。 在开发阶段,信任任何 url 可能就足够了,但在生产阶段,SSL 验证是必须的。

    看链接:Alamofire with a self-signed certificate / ServerTrustPolicy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      相关资源
      最近更新 更多