func uploadProfilePicture(data : NSData,completion: (success : Bool) -> Void) {
PKHUD.sharedHUD.contentView = PKHUDTextView(text: "Loading...")
PKHUD.sharedHUD.show()
Alamofire.upload(.POST,GlobalConstants.KUpdateProPic,multipartFormData:
{
multipartFormData in
multipartFormData.appendBodyPart(data : data, name: "image", fileName: Helper.timeStamp(), mimeType: "image/png")
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
let status : NSString = response.result.value?.valueForKey("status") as! String
if(status .isEqualToString("1")){
let profile_image : NSString = response.result.value?.valueForKey("profile_image") as! String
defaults.setObject(profile_image, forKey:"imageURL")
let fileUrl = NSURL(string: profile_image as String)
MyViewState.profile_image = (fileUrl?.lastPathComponent)!
PKHUD.sharedHUD.hide()
completion (success: true)
}else{
PKHUD.sharedHUD.hide()
completion(success : false)
}
}
case .Failure(let encodingError):
print(encodingError)
PKHUD.sharedHUD.hide()
completion(success : false)
} })
}
以上是我上传图片的代码。现在,我想通过这个上传发送一些其他参数,我想知道写入了多少字节。
我试图使用下面的链接,但我无法做到这一点。 使用 Alamofire 上传带参数的文件