0

I am trying to upload an image captured on camera to my server using Alamofire.

I have done this, but for some reason the its not going inside the if block,

 func imagePickerController(picker: UIImagePickerController,
        didFinishPickingMediaWithInfo info: [String: AnyObject]){

            print("Picker returned successfully")
            if let imageURL = info[UIImagePickerControllerMediaURL]{
                print(imageURL)
                Alamofire.upload(.POST, "http://example.com/v2/helper/uploadImageFile", file: imageURL as! NSURL).responseJSON { response in
                    debugPrint(response)
                }
            }
}

I also tried with info[UIImagePickerControllerReferenceURL], nothing is working, what's wrong with my code?

Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
  • Have you checked to see whether or not `info[UIImagePickerControllerMediaURL]` is nil? – David Smith Oct 12 '15 at 19:30
  • I think your problem is how to get the url correctly, see this ref: http://stackoverflow.com/questions/14219885/uiimagepickercontrollermediaurl-always-nil-for-a-photo – yuhua Oct 13 '15 at 04:32
  • @yuhua correct, now how do I save the UIImage so I can get a url to upload via Alamofire? – Nagendra Rao Oct 13 '15 at 05:27
  • maybe you can save the image by `UIImageWriteToSavedPhotosAlbum()` and post the UIImage as post data through `Alamofire` directly. here's the ref: http://stackoverflow.com/questions/26121827/uploading-file-with-parameters-using-alamofire – yuhua Oct 13 '15 at 05:59

0 Answers0