I'm trying to do a POST request to an endpoint with body parameters img (an image) and id (can be any number).
This works in Postman (the server never responds with fail/success though unless when the id
is missing):
However, on the iOS app side:
class func postPreviewImage(operaID: Int, image: UIImage, completion: @escaping () -> Void) {
let URL_CORDINATE = "http://artaugmentedreality.com/api/postpreview/"
print("Trying to post a preview of opera with ID:", operaID)
guard let imgData = image.jpegData(compressionQuality: 0.2) else {
print("Error while retrieving image data")
return
}
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "img", fileName: "\(Date().timeIntervalSince1970).jpg", mimeType: "image/jpeg")
multipartFormData.append(operaID.data, withName: "id")
},
to: URL_CORDINATE,
method: .post)
{ (result) in
print("Result of Alamofire call is", result)
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
case .failure(let encodingError):
print("Error while uploading image:", encodingError)
}
}
}
extension Int {
var data: Data {
var int = self
return Data(bytes: &int, count: MemoryLayout<Int>.size)
}
}
it is uploading but somehow the server is not receiving it. Could there be something wrong in my request code? I'm getting a:
Error copying matching creds. Error=-25300, query={
atyp = http;
class = inet;
"m_Limit" = "m_LimitAll";
ptcl = http;
"r_Attributes" = 1;
sdmn = "artaugmentedreality.com";
srvr = "artaugmentedreality.com";
sync = syna;
}
error code from Alamofire, perhaps because the domain isn't HTTP. However, I included the domain in the list of allowed domains in info.plist:
So I'm clueless about how to go from here.