In Swift i am using post method as a multipart image upload, The Problem is in post method when i get response then i want to stop loader but its not happen i means to say loader is not stop , I am using BProgressHUD
else every where is working fine. Here is my code . After get a image i am calling image upload method
func ImageUploadRequest_Profile()
{
BProgressHUD.showLoadingViewWithMessage("Loading...")
let myUrl = NSURL(string: "\(WebServicesUrl.GlobalConstants.ImageUpload)");
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "POST";
let param = [
"user_id" : delegate.appd_userid,
"at" : "0",
"profile_image" : "Test"
]
let boundary = generateBoundaryString()
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
compressImage()
let imageData = UIImagePNGRepresentation(img_profilePhoto.image!)
if(imageData==nil) { return; }
request.HTTPBody = createBodyWithParameters(param, filePathKey: "fileToUpload", imageDataKey: imageData!, boundary: boundary)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
// You can print out response object
// print("******* response = \(response)")
// Print out reponse body
BProgressHUD.dismissHUD(0)
}
task.resume()
}
This is get image from gallery method
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
img_profilePhoto.contentMode = .ScaleAspectFit
img_profilePhoto.image = chosenImage
ImageUploadRequest_Profile()
Please help me .