upload a single image alamofire 5.0 swift
headerFile()
AF.upload(multipartFormData: { multipartFormData in
for (key, value) in parameters {
if let temp = value as? String {
multipartFormData.append(temp.data(using: .utf8)!, withName: key)
}
if let temp = value as? Int {
multipartFormData.append("\(temp)".data(using: .utf8)!, withName: key)
}
if let temp = value as? NSArray {
temp.forEach({ element in
let keyObj = key + "[]"
if let string = element as? String {
multipartFormData.append(string.data(using: .utf8)!, withName: keyObj)
} else
if let num = element as? Int {
let value = "\(num)"
multipartFormData.append(value.data(using: .utf8)!, withName: keyObj)
}
})
}
}
if let data = imageData{
multipartFormData.append(data, withName: "file", fileName: "\(Date.init().timeIntervalSince1970).png", mimeType: "image/png")
}
},
to: endUrl, method: .post , headers: headers)
.responseJSON(completionHandler: { (response) in
print(response)
if let err = response.error{
print(err)
onError?(err)
return
}
print("Succesfully uploaded")
let json = response.data
if (json != nil)
{
let jsonObject = JSON(json!)
print(jsonObject)
}
})
}
Also in Swift:
- guard let swift
- if statement swfit
- Sending array of dictionaries with alamofire
- remove back button text nav bar swift
- double to string swift
- swift set uiimage color
- get local currency iap swift
- swift create uinavigationcontroller programmatically
- swift change status bar color
- swift comments
- swift uitableview insert cell
- swift check dictionary has key
- swift play audio file
- cross origin requests are only supported for http wkwebview
- didselectrowatindexpath not called swift
- how to delete from list tvos swiftui coredata
- special symbol ios swift
- swift sf symbol uiimage size
- swift function in a variable
- how to low case string swift
- how to get appdelegate object in swift
- init with bindings swiftui
- swift scrollview hide scrollbar
- how can i play video with url in a view in swift