swift 无法推断泛型参数“T”为Alamofire

gijlo24d  于 2023-06-21  发布在  Swift
关注(0)|答案(1)|浏览(109)

按照Alamofire文档中的多部分表单数据上传,请求应该是这样的:

AF.upload(multipartFormData: { multiPart in
    multiPart.append(data!, withName: "file", fileName: logFileName, mimeType: "multipart/form-data")
}, to: url).responseDecodable(of: DecodableType.self) { response in
    debugPrint(response)
}

但是,当我自己尝试时,我在第一行AF.upload(multipartFormData: { multiPart in上得到错误Generic parameter 'T' could not be inferred
我还没有找到一个解决方案,正确的方法是什么。任何建议都是apspeciated。

6ss1mwsb

6ss1mwsb1#

您也可以尝试以这种方式上传请求。:)

AF.upload(multipartFormData: { multiPart in
    multiPart.append(data!, withName: "file", fileName: logFileName, mimeType: "multipart/form-data")
}, to: url).response { response in
    debugPrint(response)
    guard let data = response.data, let model = try? JSONDecoder().decode(YourCustomResponse.self, from: data) else {
        return
    }
}

相关问题