我正在尝试模仿以下卷曲:
curl -v -F file=@/Users/myuser/Downloads/shelly-homekit-Shelly25.zip http://10.0.1.7/update
为了使用 curl 命令,我下载了 zip 文件并将其保存到我的计算机中。
我的应用程序应该下载 zip 文件,将其存储到设备并上传到服务器。
我尝试将其作为文件和数据上传,但均未成功:
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)
}
}
}
}
我收到以下错误:
谢谢您的帮助