Alamofire上载包含多部分/表单数据的图片 [英] Alamofire upload image with multipart/form-data
问题描述
我正在寻找一个有效的示例代码,以使用Alamofire上载具有多部分/表单数据的图像
i am looking for a working sample code to upload an image with multipart/form-data using Alamofire
我无法使用此代码来处理我的项目
i can't get this code to work with my project
Alamofire.upload(
.POST,
URLString: "http://httpbin.org/post",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
multipartFormData.appendBodyPart(fileURL: rainbowImageURL, name: "rainbow")
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { request, response, JSON, error in
println(JSON)
}
case .Failure(let encodingError):
println(encodingError)
}
}
)
此代码有此错误Could not find member 'POST'
有人说,如果您使用Alamofire.Method.POST
,它将解决此问题,但我却收到此错误,而Cannot invoke 'upload' with an argument list of type '(Method, URLString: String, multipartFormData: (_) -> _, encodingCompletion: (_) -> _)'
some people said that if you use Alamofire.Method.POST
it will fix the issue but i got this error instead Cannot invoke 'upload' with an argument list of type '(Method, URLString: String, multipartFormData: (_) -> _, encodingCompletion: (_) -> _)'
如果有人对此错误有解释或有其他可行的示例,请多多帮助.
if anyone has explanation for this error or have another working sample , would appreciate your help.
推荐答案
这是cocoapods的安装问题,我不得不将podfile更新为这样
it was cocoapods installation issue i had to update the podfile to be like this
platform :ios, '8.0'
use_frameworks!
target 'ProjectName' do
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
end
target 'ProjectNameTests' do
end
以便我可以获得支持MultipartFormData
有关更多信息,请参见答案
for more information see this Answer
这篇关于Alamofire上载包含多部分/表单数据的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!