Alamofire image upload with PUT

I actually recently had the same requirements (except I needed PNG instead of JPG).

Here is how you go about it.

let compressionQuality: CGFloat = 0.8
guard let imageData = UIImageJPEGRepresentation(image, compressionQuality) else {
    print("Unable to get JPEG representation for image \(image)")
    return
}

let headers = [
    "Content-Type": "image/jpeg"
]

// presignedUrl is a String

Alamofire.upload(imageData, to: presignedUrl, method: .put, headers: headers)
    .responseData {
        response in

        guard let httpResponse = response.response else {
             print("Something went wrong uploading")
             return
        }

        if let publicUrl = presignedUrl.components(separatedBy: "?").first { 
             print(publicUrl)
        }
}

Have you changed your capabilities to allow background services?

enter image description here

Something that worked to me:

   let imageData = UIImageJPEGRepresentation(image  , 0.7)

      Alamofire.upload(imageData!, to: url, method: .put, headers: nil).responseJSON(completionHandler: { (response) in
                debugPrint(response)
            })