简体   繁体   中英

How can I upload images to Parse.com programatically?

I have a very large set of images to upload, and the best way to do that is to let my app do it for me. But after copy and pasting the code from Parse's docs, it doesn't work.

var image = NSData(contentsOfURL: NSURL(string: "XY1_EN_1.jpg")!)!
@IBAction func xyButton1(sender: AnyObject) {

    for var i = 1; i < 147; i++ {

        let imageData = UIImageJPEGRepresentation(image)
//ERROR on line above: Missing argument for parameter #2 in call

        let imageFile = PFFile(name:"image.png", data:imageData)

        var userPhoto = PFObject(className:"Cards")
        userPhoto["imageName"] = "XY1_EN_1"
        userPhoto["imageFile"] = imageFile
        userPhoto.save()    
    }
}

What am I doing wrong?

There are two problems with the code. UIImageJPEGRepresentation( : :) takes two parameters, a UIImage and a float. Right now you are calling UIImageJPEGRepresentation(_:) and giving it NSData. If you want to use that method to get NSData from an Image, you need to make self.image of UIImage type instead of NSData. Maybe init your variable image with UIImage(named: "imageName") if the image is bundled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM