使用Alamofire

时间:2015-10-27 06:20:12

标签: swift http-post alamofire

我正在尝试使用params上传文件,但它失败了。 下面的代码有问题吗?

参考 Uploading file with parameters using Alamofire

夫特

Alamofire.upload(.POST, url, multipartFormData: { (multipartFormData) -> Void in
            let fd = UIImageJPEGRepresentation(image,0.8)!
            multipartFormData.appendBodyPart(data: fd, name: "image", fileName: "image.jpg", mimeType: "image/jpeg")
            for (k, v) in params {
                let d = v.dataUsingEncoding(NSUTF8StringEncoding)!
                multipartFormData.appendBodyPart(data: d, name: k)
            }
            }) { (encodingResult) -> Void in
                switch encodingResult {
                case .Success(let upload, _, _):
                    upload.responseJSON { response in
                        if response.result.isSuccess {
                            print("success")
                        } else {
                            print("fail")
                        }
                    }
                case .Failure(let encodingError):
                    self.view.makeToastCenter(message: "fail \(encodingError)")
                }

0 个答案:

没有答案