@Fujia 응답 외에도 예제를 추가하고 싶습니다. 이것은 최근에 png 파일을 게시 할 때 사용했던 방법입니다.
func WasperEntrepriseImageUploadCall(method: Alamofire.Method, imageData: NSData, parameters: [String: AnyObject]?, headers: [String: String]?, urlToPost: String,
progressionHandler: (bytesWritten: Int, totalBytesWritten: Int, totalBytesExpected: Int) ->(),
completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<AnyObject,NSError>, NSData?) ->()){
Alamofire.upload(
method, urlToPost, headers: headers,
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(data: imageData, name: "file", fileName: "doesntmatter", mimeType: "image/png")
if let params = parameters{
for (key, value) in params {
multipartFormData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding)!, name: key)
}
}
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.progress { bytesWritten, totalBytesWritten, totalBytesExpectedToWrite in
progressionHandler(bytesWritten: Int(bytesWritten), totalBytesWritten: Int(totalBytesWritten), totalBytesExpected: Int(totalBytesExpectedToWrite))
}
upload.response { response in
}.validate()
.responseJSON { response in
if let resp = response.response{
print(resp.statusCode)
print(response.result.value) // result of response serialization
}
completionHandler(response.request,response.response,response.result, response.data)
}
case .Failure(let encodingError):
print(encodingError)
}
}
)
}
가장 좋은 해결책은 아니지만 가장 먼저 시작해야합니다. 내가 믿는 SwiftyJSON과 Alamofire 3.0이 필요합니다. 유용하게 사용할 수있는 진행을위한 완료 처리기를 제공합니다. 여기에서 자세한 답변을 찾을 수 있습니다. Uploading file with parameters using Alamofire