ios - Saving & retrieving images on Firebase -
this question has answer here:
- swift2 retrieving images firebase 2 answers
on process of trying firebase, possible replacement parse.com (unfortunately disappear), have saved png image online using code below, in swift.
let fn = self.toolbox.getdocumentsdirectory().stringbyappendingpathcomponent("m0-1.png") let im = uiimage(contentsoffile: fn), dat = uiimagepngrepresentation(im!), b64 = dat?.base64encodedstringwithoptions(.encoding64characterlinelength), qs = ["string": b64!], r = diltrootref.childbyappendingpath("zs"), = ["img": qs] r.setvalue(us)
the saving part seems work, how suppose image saved? have tried far failed.
i recommend retrieving images using observesingleeventoftype(:_)
, because it's one-time read.
once have string value synchronized, can use nsdata()
initializer, , create uiimage
.
imageref.observesingleeventoftype(.value) { (imagesnap: fdatasnapshot!) in let base64string = imagesnap.value as! string let decodeddata = nsdata(base64encodedstring: base64string, options: nsdatabase64decodingoptions(rawvalue: 0)) let image = uiimage(data: decodeddata!) }
check out example repo on using base64 images in uitableview.
Comments
Post a Comment