Deseo enviar可以在IOS上进行图像处理,没有Deseo recodificarla a BASE64,deseo enviarla como“文件”
他打算用Alamofire.upload禁运我,直到siguiente错误:“无法调用类型为'(UIImage,withName:String)'的参数列表的'append'” manda el错误“表达式类型在没有更多上下文的情况下是模棱两可的”,el codigo utilizado es el siguiente:
func uploadMultiformData1(){
//variables
let usuario = "alfred"
let datosAdd = "otros datos"
//endRegion
//parameters
let parametros =
[
"idUsuario": usuario,
"aditionalData": datosAdd
] as [String : AnyObject]
//endRegion
//图片省:@IBOutlet弱var mainImageView:UIImageView!
let image = mainImageView.image
let imageData = image!.pngData()
// CREATE AND SEND REQUEST ----------
Alamofire.upload(multipartFormData: { (multipartFormData) in
for (key, item) in parametros {
multipartFormData.append(item.data(using:.utf8)!, withName: key)
}
multipartFormData.append(imageData!, withName: "image", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
}, to:url)
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (Progress) in
print("Upload Progress: \(Progress.fractionCompleted)")
})
upload.responseJSON { response in
//self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// self.showSuccesAlert()
//self.removeImage("frame", fileExtension: "txt")
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
case .failure(let encodingError):
//self.delegate?.showFailAlert()
print(encodingError)
}
}
}
EL结果查询: 1.图片浏览和使用ImageView 2. Adjuntarla al envio en tipo POST 3. El servidor responsee JSON