gpt4 book ai didi

ios - Swift 3 Alamofire 分段上传

转载 作者:IT王子 更新时间:2023-10-29 05:00:24 26 4
gpt4 key购买 nike

由于迁移到 Swift 3,我发现很难编译我使用 Alamofire 的项目。

上传multipartFormData时出现的问题:

Alamofire.upload(.POST, URL, headers: headers, multipartFormData: {
multipartFormData in
.
.
.
})

Ambiguous reference to member 'upload(_:to:method:headers:)'

非常感谢任何帮助,提前致谢!

已解决:

 Alamofire.upload(multipartFormData: { (multipartFormData) in

multipartFormData.append(fileData, withName: "file_pack", fileName: "file_pack", mimeType: "text/plain")


for (key, value) in self.parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, with: URL2, encodingCompletion: { (result) in

switch result {
case .success(let upload, _, _):

upload.responseJSON { response in
self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// self.showSuccesAlert()
self.removeImage("frame", fileExtension: "txt")
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}

case .failure(let encodingError):
self.delegate?.showFailAlert()
print(encodingError)
}

})

上传方法应该如何在 Swift 3 中实现

最佳答案

例如,在 Swift 3 中使用 Alamofire 4.0.0:

(确保您已准备好 4.0.0,因为看起来您还没有更新您的 Alamofire)

Alamofire.upload(multipartFormData: { (multipartFormData) in
// code
}, to: URL, encodingCompletion: { (result) in
// code
})

Alamofire.upload(multipartFormData: { (multipartFormData) in
// code
}, with: URL, encodingCompletion: { (result) in
// code
})

所以headers需要通过URL请求传递:

let URL = try! URLRequest(url: "http://example.com", method: .get, headers: headers)

关于ios - Swift 3 Alamofire 分段上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39592085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com