-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipartImages
51 lines (44 loc) · 1.85 KB
/
MultipartImages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
func UPLOD()
{
//Parameter HERE
let parameters = [
"id": "1221",
"docsFor" : "wqww"
]
//Header HERE
let headers = [
"token" : "W2Y3TUYS0RR13T3WX2X4QPRZ4ZQVWPYQ",
"Content-type": "multipart/form-data",
"Content-Disposition" : "form-data"
]
let image = UIImage.init(named: "imagename")
let imgData = UIImageJPEGRepresentation(image!, 0.7)!
Alamofire.upload(multipartFormData: { multipartFormData in
//Parameter for Upload files
multipartFormData.append(imgData, withName: "file",fileName: "imagename.png" , mimeType: "image/png")
for (key, value) in parameters
{
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, usingThreshold:UInt64.init(),
to: "http:API-for-url-her", //URL Here
method: .post,
headers: headers, //pass header dictionary here
encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
print("the status code is :")
upload.uploadProgress(closure: { (progress) in
print("something")
})
upload.responseJSON { response in
print("the resopnse code is : \(response.response?.statusCode)")
print("the response is : \(response)")
}
break
case .failure(let encodingError):
print("the error is : \(encodingError.localizedDescription)")
break
}
})
}