I was wondering if anyone can help me, I'm new to app developing I am uploading images from my app to parse with no problem with help from parse documentation.
let imageData = UIImagePNGRepresentation(scaledImage)
let imageFile: PFFile = PFFile(data: imageData)
var userPhoto = PFObject(className: "postString")
userPhoto["imageFile"] = imageFile
userPhoto.saveInBackground()
but when i add the code to retrieve the image back, I'm a bit lost :/
let userImageFile = anotherPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if !error {
let image = UIImage(data:imageData)
}
}
where is the "anotherPhoto" coming from ? Parse did say "Here we retrieve the image file off another UserPhoto named anotherPhoto:"
Open ViewController. swift and create an outlet with name imageView of type UIImageView! , an implicitly unwrapped optional. The idea is simple. The view controller downloads an image from a URL and displays it in its image view.
First one is to drag and drop an image file from Finder onto the assets catalog. Dragging the image will automatically create new image set for you. Drag and drop image onto Xcode's assets catalog. Or, click on a plus button at the very bottom of the Assets navigator view and then select “New Image Set”.
An object that manages image data in your app.
anotherPhoto
would be an instance of your postString
(userPhoto
in your upload example). The file downloading example that would work for you is like this:
let userImageFile = userPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if !error {
let image = UIImage(data:imageData)
}
}
Any PFFile must be referenced from a normal PFObject or it cannot be retrieved. PFFile objects themselves will not show up in the data browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With