in app, users can select photo gallery upload. after user selects photo, following code gets called:
func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingimage image: uiimage!, editinginfo: [nsobject : anyobject]!) { self.dismissviewcontrolleranimated(true, completion: { () -> void in }) }
i need upload image in method, don't know how upload photo server. can post text following code don't know how use photo/s:
let request = nsmutableurlrequest(url: nsurl(string: "url")!) request.httpmethod = "post" let poststring = "username=\(self.username)" request.httpbody = poststring.datausingencoding(nsutf8stringencoding) let task = nsurlsession.sharedsession().datataskwithrequest(request) { data, response, error in } task.resume()
how can upload selected photo server above code?
what you're looking called base64
encoding,
called this, , added post
request.
let base64string = imagedata.base64encodedstringwithoptions(.allzeros) println(base64string)
a larger answer can found here.
good luck!
Comments
Post a Comment