问题
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)
}
}
)
This code has this error Could not find member 'POST'
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.
回答1:
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
so that i can get the latest version of Alamofire that support MultipartFormData
for more information see this Answer
来源:https://stackoverflow.com/questions/31545620/alamofire-upload-image-with-multipart-form-data