ios - How to get URL from UIImage? -


i have ios app in there 2 ways user can picture:

  1. select photos library (uiimagepickercontroller)

  2. click custom made camera

here code clicking image custom camera (this within custom class called camera, subclass of uiview)

func clickpicture(completion:@escaping (uiimage) -> void) {      guard let videoconnection = stillimageoutput?.connection(withmediatype: avmediatypevideo)  else { return }      videoconnection.videoorientation = .portrait     stillimageoutput?.capturestillimageasynchronously(from: videoconnection, completionhandler: { (samplebuffer, error) -> void in          guard let buffer = samplebuffer else { return }          let imagedata = avcapturestillimageoutput.jpegstillimagensdatarepresentation(buffer)         let dataprovider = cgdataprovider(data: imagedata! cfdata)         let cgimageref = cgimage(jpegdataprovidersource: dataprovider!, decode: nil, shouldinterpolate: true, intent: .defaultintent)          let image = uiimage(cgimage: cgimageref!, scale: 1, orientation: .right)          completion(image)       }) } 

here how click image within viewcontroller:

@ibaction func clickimage(_ sender: anyobject) {     cameraview.clickpicture { (image) in         //use "image" variable     } } 

later, attempt upload picture user's icloud account using cloudkit. receive error saying record large. came across this post, says use ckasset. however, constructor ckasset requires url.

is there generic way can url uiimage? otherwise, how can url image clicked using custom camera (i have seen other posts getting url uiimagepickercontroller)? thanks!

ckasset represents external file (image, video, binary data , etc). why requires url init parameter.

in case recommend use following steps upload large image cloudkit:

  1. save uiimage local storage (e.g. documents directory).
  2. initialize ckasset path image in local storage.
  3. upload asset cloud.
  4. delete image local storage when uploading completed.

here code:

// save image. let path = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true).first! let filepath = "\(path)/myimagename.jpg"  uiimagejpegrepresentation(image, 1)!.writetofile(filepath, atomically: true)  let asset = ckasset(fileurl: nsurl(fileurlwithpath: filepath)!) // upload asset here.  // delete image. {     try filemanager.default.removeitem(atpath: filepath) } catch {     print(error) } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -