gpt4 book ai didi

ios - Alamofire:取消(暂停)文件上传

转载 作者:可可西里 更新时间:2023-11-01 06:02:29 53 4
gpt4 key购买 nike

我正在使用 Alamofire 上传一个文件:

    Alamofire.Manager.upload(
APIManager.Router.UploadFileRoute,
multipartFormData : { multipartFormData in
multipartFormData.appendBodyPart(data: audioData, name: "file", fileName: "file.m4a", mimeType: "audio/m4a")
}, encodingCompletion: { result in
switch result {
case .Success(let request, _, _):
break
case .Failure(let encodingError):
break
}
})

文件上传开始后如何取消(暂停)?

documentation建议我在 Request 对象上调用 suspend() ,但是如何使用上面的文件上传 API 获取 Alamofire.Request 对象?此 API 不返回任何 Alamofire.Request 对象。

最佳答案

事实证明请求仅在编码后准备就绪(参见内联注释)

Alamofire.Manager.upload(
APIManager.Router.UploadFileRoute,
multipartFormData : { multipartFormData in
multipartFormData.appendBodyPart(data: audioData, name: "file", fileName: "file.m4a", mimeType: "audio/m4a")
}, encodingCompletion: { result in
switch result {
case .Success(let request, _, _):
// Reference the request here (will get here immediately)
request.responseJSON { response in
// This closure executes only after request succeeds or fails
}
break
case .Failure(let encodingError):
break
}
})

关于ios - Alamofire:取消(暂停)文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39882696/

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