我想使用post
中的swift3
方法上传图片和数据。
这是我的代码:
func dataToUpload() {
let imageData: NSData = UIImageJPEGRepresentation(myImage.image!, 0.4)! as NSData
let base64String = imageData.base64EncodedString()
let imageStr = imageData.base64EncodedString(options: .lineLength64Characters)
let param=[
"Is_checkin" : "0",
"Description" : self.cookingText.text!,
"Videolink" : "",
"Post_image" : base64String ,
"Created_by" : "4490",
"Created_on" : "29/Aug/2017" ,
] as [String : Any]
Alamofire.request("https://www.zdoof.com/api/zTimeline/insert_post", method: .post, parameters: param, encoding: JSONEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case .success(_):
if response.result.value != nil{
print(response.result.value!)
}
break
case .failure(_):
print(response.result.error!)
break
}
}
}
但图片无法上传。
请帮助上传