I'm working on an iOS app that works with Apache Usergrid. So far everything is working, I can register users, log in, query...
btw: I'm working with Usergrid 2.1.0 release, running on my own server.
Now I want to store the users profile picture. I do it like so:
let image = UIImage(named:"user.png")!
let asset = UsergridAsset(fileName: "profilepic", image: image, imageContentType: .Png)!
Usergrid.currentUser!.uploadAsset(asset, progress: nil) { (response, asset, error) -> Void in
if response.ok {
print("Picture saved")
} else {
self.showErrorMessage("Picture couldn't be saved")
print(response.description)
}
}
this seems to be working, since when looking into Portal I can see something about "file-metadata" in my users' entity. Now the problem: How do I get the Image back? I tried the following:
Usergrid.currentUser?.downloadAsset("image/png", progress: nil, completion: { (asset, error) -> Void in
if (error == nil) {
if let image = UIImage(data: (asset?.data)!) {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.profileImageButton.setImage(image, forState: .Normal)
})
}
}
}
but everytime I get the Error "Entity does not have an asset attached" when in fact I can see the image with the help of Firefox RESTClient. What am I doing wrong?