I am trying to mimic the following curl:
curl -v -F file=@/Users/myuser/Downloads/shelly-homekit-Shelly25.zip http://10.0.1.7/update
to use the curl command I downloaded the zip file and saved it to my computer.
My app should download the zip file, store it to the device and upload it to the server.
I tried both uploading it as a file and as Data with no success:
let destination: DownloadRequest.Destination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent("shelly-homekit-Shelly1PM.zip")
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
AF.download("https://rojer.me/files/shelly/shelly-homekit-Shelly1PM.zip", to: destination).response { response in
debugPrint(response)
if response.error == nil, let zipPath = response.fileURL?.path {
let url = URL(string: zipPath)!
let headers: HTTPHeaders = [
.contentType("multipart/form-data")
]
if let data = try? Data(contentsOf: url) {
AF.upload(data, to: "http://"+dev.ipAddress+"/update",headers: headers).responseDecodable(of: HTTPBinResponse.self) { response in
debugPrint(response)
}
}
}
}
I get the following error:
Thank you for your help