I am developing an application in Swift language. I set up a backend service with amazon s3 service and fast api. I want to save an image with .png extension to this backend service. I am getting 422 "422 Unprocessable Entity" error from the server while sending the photo. I know this error occurs because the format is wrong but I couldn't fix the problem. I am sharing the part of the code I wrote in swift and the fast-api screenshot.
`func uploadImage2(paramName: String, fileName: String, image: UIImage, uid: String) {
let urlString = ""
let url = NSURL(string: urlString)!
let requestURL = NSMutableURLRequest(url: url as URL)
requestURL.httpMethod = "POST"
requestURL.addValue("multipart/form-data", forHTTPHeaderField: "Content-Type")
let body = NSMutableData()
body.append("file=@\(image)".data(using: String.Encoding.utf8)!)
body.append("type=image/png".data(using: String.Encoding.utf8)!)
requestURL.httpBody = body as Data
let task = URLSession.shared.dataTask(with: requestURL as URLRequest){ data,response,error in
if let data = data {
let sendedData = String(data: data, encoding: .utf8)
print("Succesful + \(String(describing: sendedData))")
} else {
print("Error: \(String(describing: error))")
}
}
task.resume()
}`
I'm having trouble uploading photos to the server.