如何使用带有以下参数的alamofire在swift中发布帖子请求(来自邮递员的截图)图像是文件类型,标题是文本类型
我正在尝试这样:
let headers = [
"Content-Type": "application/form-data",
"X-App-Token": user.token!
]
Alamofire.upload(multipartFormData:{ multipartFormData in
multipartFormData.append(UIImagePNGRepresentation(imgToSend)!, withName: "image")
multipartFormData.append(titleToSend.data(using: .utf8)!, withName: "title")},
usingThreshold:UInt64.init(),
to: url!,
method:.post,
headers:headers,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
})
但是我收到了错误: [BoringSSL]函数boringssl_session_errorlog:第2868行[boringssl_session_write] SSL_ERROR_SYSCALL(5):库外部操作失败
和(这很奇怪)调试器进入.success但是当我记录响应时,api有错误
答案 0 :(得分:3)
尝试更改
multipartFormData.append(UIImagePNGRepresentation(imgToSend)!, withName: "image")
到
multipartFormData.append(UIImagePNGRepresentation(imgToSend)!, withName: "image", fileName: "sample.png", mimeType: "image/png")
如果您收到如下警告:
第2878行[boringssl_session_write] SSL_ERROR_SYSCALL(5):操作 在图书馆外部失败
你可以简单地忽略它。这只是意味着TLS连接上的操作失败,因为TLS已通过close_notify
警报关闭。这种事情本身并不是问题。
您可以在Xcode中禁用操作系统日志记录,以使其消失。打开项目窗口,转到Project - >方案 - >编辑方案...并添加" OS_ACTIVITY_MODE"到Environment Variables部分并将其值设置为"禁用"。当您重新运行应用程序时,现在不应出现这些警告。