Search code examples
phpjsonswiftpostalamofire

How do I send POST Json and Image to php alamofire


I am able to send post data as json fine from swift using this code:

private func alamoFireAjax(url: String, parameters: Parameters, callback: @escaping (DataResponse<Any>) -> Void) {
    Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON(completionHandler: callback)
}

But I want to send a image along with the data that this function is sending. How do I do that in alamofire, or do I need a different framework.


Solution

  • You need convert(encode) image to base64 and send to PHP as a string, after receiving post PHP can decode it and save in the storage or save base64 string.