I'm using Swift4, I had uploaded image to server using this code
class func uploadMultipleAdvertisementImage(photos: UIImage, completion: @escaping (_ error: Error?, _ sucess: Bool, _ image_id: Int)-> Void) {
let url = URLs.uploadImages
var images = [Data]()
Alamofire.upload(multipartFormData: { (form: MultipartFormData) in
if let data = UIImageJPEGRepresentation(photos , 0.5) {
form.append(data, withName: "images", fileName: "photo.jpeg", mimeType: "image/jpeg")
}
}, usingThreshold: SessionManager.multipartFormDataEncodingMemoryThreshold, to: url, method: .post, headers: nil) { (result: SessionManager.MultipartFormDataEncodingResult) in
switch result {
case .failure(let error):
print(error)
completion(error, false, 0)
case .success(request: let upload, streamingFromDisk: _, streamFileURL: _):
upload.uploadProgress(closure: { (progress: Progress) in
print(progress)
})
.responseJSON(completionHandler: { (response: DataResponse<Any>) in
switch response.result
{
case .failure(let error):
print(error)
completion(error, false, 0)
case .success(let value):
let json = JSON(value)
print(json)
if(json["msg"] == "image uploaded successfully") {
let image_id = json["image_id"].int ?? 0
print("hiiiiiiiiii", image_id)
completion(nil, true, image_id)
}
}
})
}
}
}
it worked successfuly, but I want to upload array of images to the server with name "images". there is any way to upload array of images to server rather than upload one?