Thursday, August 6, 2015

Save a File to a Parse Table

JAVA

// Prepare File
byte[] photoBytes = myPhotoObject.toByteArray();
ParseFile photo = new ParseFile("myPicture.jpg", photoBytes);
photo.saveInBackground();

// Now save to Parse Table
ParseObject myParseTable = new ParseObject("MyParseTable");
myParseTable.put("ID", "1");
myParseTable.put("Photo", photo);
myParseTable.saveInBackground();


SWIFT

// Prepare File
let imageData = UIImagePNGRepresentation(image)
let photo= PFFile(name:"myPicture.jpg", data:imageData)

// Now save to Parse Table
var myParseTable = PFObject(className:"MyParseTable")
myParseTable["ID"] = "1"
myParseTable["Photo"] = photo

myParseTable.saveInBackground()

No comments:

Post a Comment