user_id:22
name:sudhir
email:sudhir@gmail.com
mobile:rty
profile_image:11.jpg
lat:28.65456455
lng:77.5445454
pin_code:201301
state:UP
city:Noida
id_card:adhar.png
id_no:56787575
id_name:Adhaar
address:Noid UP, India
我正在使用此代码发送带有两个不同参数且带有主体的图像
func createBodyWithParameters(parameters: [String: String]?, filePathKey: String?, imageDataKey: NSData,filePathKey1: String?,imageDataKey1: NSData, boundary: String) -> NSData {
let body = NSMutableData();
if parameters != nil {
for (key, value) in parameters! {
body.appendString(string: "--\(boundary)\r\n")
body.appendString(string: "Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n")
body.appendString(string: "\(value)\r\n")
}
}
let filename = "user-profile.jpg"
let mimetype = "image/jpg"
body.appendString(string: "--\(boundary)\r\n")
body.appendString(string: "Content-Disposition: form-data; name=\"\(filePathKey!)\"; filename=\"\(filename)\"\r\n")
body.appendString(string: "Content-Type: \(mimetype)\r\n\r\n")
body.append(imageDataKey as Data)
body.appendString(string: "\r\n")
// let filename = "user-profile.jpg"
body.appendString(string: "--\(boundary)\r\n")
body.appendString(string: "Content-Disposition: form-data; name=\"\(filePathKey1!)\"; filename=\"\(filename)\"\r\n")
body.appendString(string: "Content-Type: \(mimetype)\r\n\r\n")
body.append(imageDataKey1 as Data)
body.appendString(string: "\r\n")
body.appendString(string:"--\(boundary)--\r\n")
return body
}