text 分段上传协议扩展

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 分段上传协议扩展相关的知识,希望对你有一定的参考价值。

extension APIRequestHandler {

    private func uploadToServerWith<T: CodableInit>(_ decoder: T.Type, data: UploadData, request: URLRequestConvertible, parameters: Parameters?, progress: ((Progress) -> Void)?, completion: CallResponse<T>) {
        
        upload(multipartFormData: { (mul) in
            mul.append(data.data, withName: data.name, fileName: data.fileName, mimeType: data.mimeType)
            guard let parameters = parameters else { return }
            // adding keys and values to the multipart file,
            // although I wanted to pass them with the URL Request but it didn't work somehow,
            // so until I figured it out I'm putting it here.
            for (key, value) in parameters {
                mul.append("\(value)".data(using: String.Encoding.utf8)!, withName: key as String)
            }
        }, with: request) { (response) in
            switch response {
            case .success(let requestUp, _, _):
                requestUp.responseData(completionHandler: { (results) in
                    self.handleResponse(results, completion: completion)
                }).responseString(completionHandler: { (string) in
                    print(string.result.value)
                })
                
            case .failure(let error):
                completion?(ServerResponse<T>.failure(error as? LocalizedError))
            }
            
        }
    }
    

以上是关于text 分段上传协议扩展的主要内容,如果未能解决你的问题,请参考以下文章

php 上传大文件 插件 都有哪些

互联网协议 — Segment Routing(分段路由网络)— SRv6

互联网协议 — Segment Routing(分段路由网络)— SRv6

求php怎么实现web端上传超大文件

AWS S3 大文件分片上传

text QUploader组件的扩展使其能够上传文件抛出Firebase存储