如何在Alamofire中处理多部分/相关数据?

时间:2018-09-17 10:32:22

标签: ios alamofire multipart

我的后端服务器图像的多部分/相关数据。如何使用Alamofire在iOS客户端中处理它?

1 个答案:

答案 0 :(得分:0)

要从IOS上传多部分图片,示例代码如下:

 if let URL = try? URLRequest(url: url, method: .post, headers: nil) {
        Alamofire.upload(multipartFormData: { (multipartFormData) in
            multipartFormData.append(UIImageJPEGRepresentation(image, 0.001), withName: "file", fileName: params.imageName, mimeType: "image/jpeg")
        }, with: URL) { (result) in
            switch result {
            case .success(let upload, _, _):
                //Enter Success Code
            case .failure:
                //Enter failure Code
            }
        }

希望有帮助。