我正在尝试转换我的上传图像程序。但停滞不前发生了几个问题。
我想要这个问题的任何建议。
下面是以前使用 Alamofire 3 的代码。
Alamofire.upload(
.POST,
"https://uploadURL",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(data: imageData!, name: "image", fileName: nowString + "To" + receiverString! + ".jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.appendBodyPart(data: value!.data(using: String.Encoding.utf8)!, name: key)
}
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseString(completionHandler: { (response) in
debugPrint(response)
})
case .failure(let encodingError):
print(encodingError)
}
}
)
下面是为 Alamofire 4.0.1 和 swift 3 编写的当前代码。(不完整)
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(data: imageData!, name: "image", fileName: nowString + "To" + receiverString! + ".jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(data: value!.data(using: String.Encoding.utf8)!, name: key)
}
},to:"https://uploadURL",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseString(completionHandler: { (response) in
debugPrint(response)
})
case .failure(let encodingError):
print(encodingError)
}
}
)
围绕“multipartFormData”生成错误消息。
'append' 的重载存在这些部分匹配的参数列表:(Data, withName: String, fileName: String, mimeType: String), (URL, withName: String, fileName: String, mimeType: String)
将“Any”转换为“AnyObject”或使用“as!” 强制向下转换为更具体的类型以访问成员
我正在寻找这个问题的解决方案......