gpt4 book ai didi

ios - 我如何在 Alamofire 4.0 中添加带有上传进度百分比标签的进度条

转载 作者:行者123 更新时间:2023-11-28 15:58:33 31 4
gpt4 key购买 nike

我正在尝试通过 Alamofire 4.0 将视频上传到服务器,我想添加进度条以显示上传过程中上传进程的百分比,我如何通过从 Alamofire 上传的相同功能来实现这一点。

我的上传功能代码:

Alamofire.upload(multipartFormData: { multipartFormData in



multipartFormData.append(url.absoluteURL!, withName: "videoFile", fileName: "alaa", mimeType: "mov")
multipartFormData.append("video".data(using: .utf8)!, withName: "load")
multipartFormData.append("record".data(using: .utf8)!, withName: "type")


}, with: URL, encodingCompletion: { (result) in
// code
print("uploaded")
})

最佳答案

直接引用 AlamoFire 文档:

Upload Progress

While your user is waiting for their upload to complete, sometimes it can be handy to show the progress of the upload to the user. Any UploadRequest can report both upload progress and download progress of the response data using the uploadProgress and downloadProgress APIs.

let fileURL = Bundle.main.url(forResource: "video", withExtension: "mov")

Alamofire.upload(fileURL, to: "https://httpbin.org/post")
.uploadProgress { progress in // main queue by default
print("Upload Progress: \(progress.fractionCompleted)")
}
.downloadProgress { progress in // main queue by default
print("Download Progress: \(progress.fractionCompleted)")
}
.responseJSON { response in
debugPrint(response)
}

关于ios - 我如何在 Alamofire 4.0 中添加带有上传进度百分比标签的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41408119/

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