0

I have looked and looked in Parse docs, SO and Google, and can not find an example of storing a plain ol' Core Data SQLite file to Parse.com. Initially I just want to store the Core Data file as a backup; eventually I want to add FTASync and then ability for others to utilize the stored Core Data file from this iOS app.

Is there an example of doing this without using a PFObject? Can someone point me to a place in the Parse docs where I can find out how to do this?

3
  • So are you storing the SQLite file or the objects (against classes defined in Parse)? Commented Oct 11, 2013 at 21:26
  • I'm doing neither; I am getting my "ducks lined up"! I need a good "getting started" with Parse where it describes how to take a Core Data d/b and store it on Parse.com Commented Oct 11, 2013 at 23:03
  • I'm using RestKit and the Parse RESTful interface. Not a PFObject in sight... Commented Oct 12, 2013 at 7:46

1 Answer 1

2

No, you cannot do this without any PFObject. Theoretically you can save backups just with

- (void)createBackupFromSQLiteStorageAtPath:(NSString*)path
{
    NSString *name = [[NSDate date] description]; // for example, stringified date will act as name
    PFFile *backup = [PFFile fileWithName:name contentsAtPath:path];
    [backup saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
    {
        if (error)
        {
            // handle
        }
        else
        {
            // success
        }
    }];
}

But! If you want to access it from parse's fileserver you'll need to keep PFFile objects somehow (you can also store PFFile's url property - but it's hack) - and here's the case where PFObject comes to help. Assuming you have backed up your store already:

- (void)storeBackupFile:(PFFile*)file
{
    PFObject *backup = [PFObject objectWithClassName:@"Backup"];
    [backup setObject:file forKey:@"file"];
    [backup setObject:[PFUser currentUser] forKey:@"user"];
    [backup saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
        {
            if (error)
            {
                [backup saveEventually];
            }
            else
            {
                // success
            }
        }];
}

So after this you'll have Backup object in parse database, with link to backup file and user that created backup.
Some more considerations:
1) It's good to organize such backup as NSOperation subclass.
2) It's bad idea to store backups with Parse in such way. File storage on Parse is very expensive resource. Also, PFFile has local cache - your storage will be duplicated each time you make backup, so app's size will increase dramatically with often backups.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much; this is exactly what I was looking for! Where can I find more information on what you are describing? As I indicated, I have looked and looked, to no avail. A good "getting started" doc would be most appreciated. :D
Unfortunately i don't know such kind of guide=( I'm not sure, but i think none of Parse examples (parse.com/tutorials) fits your task. However, i suggest you to consider (parse.com/tutorials/anypic) example, first three steps - they have all you need: saving file, saving pfobject. This short tutorial + parse docs at parse.com/docs/ios/api (Main classes are PFObject,PFFile,PFQuery,PFUser) will give you understanding of main framework possibilities. But don't use anypic as base of your own project - it may contain old version of framework!
You don't need to use PFObject. Parse offers multiple different APIs (and PFObject is really just a wrapper around their RESTful interface).
@Wain, going further it's possible not to use PFFile at all - and implement uploading/downloading via HTTP (and honestly saying it works faster then PFFile's save/getData). However, if task doesn't need network performance optimizations (and i believe that backing up doesn't actually need it) it's better to use ready & tested & vendor-provided solutions like PFFile and PFObject instead of inventing own bicycle. Another problem is file storage... Parse's cool for database and has extremely expensive file storage. Amazon S3 is much better for backup purposes... But this is off-topic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.