user3827344
user3827344

Reputation:

PFObject won't save PFFile PArse

I can't seem to set a Pffile object as a value for a Pfobject key in Objective-C. I'm trying to save NSData from an AVAudioPlayer in a PFfile. If I do the folllowing:

NSData * audioData=[self.shoutInfoArray objectAtIndex:1];
PFFile * audiofile=[PFFile fileWithName:@"shoutData" data:audioData];
bool saved=[audiofile save]; //This bool is positive, so it does save!?
[shout fetchIfNeeded];
shout[@"audioData"]=audiofile; //BUGGY LINE

I get the following error:

Error: invalid type for key audioData, expected bytes, but got file (Code: 111, Version: 1.2.20)

Couldn't find why?

Upvotes: 0

Views: 856

Answers (2)

Roman
Roman

Reputation: 366

Clear your database. I mean drop column audioData. It seams something wrong with types.

Upvotes: 0

Nimisha Patel
Nimisha Patel

Reputation: 406

To Save a PFFile object as a part of PFObject:Also check file size should not be greater than 10MB.

PFFile * audiofile=[PFFile fileWithName:@"shoutData.aif" data:audioData];

[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

 //Use async call.
 // It is compulsory to save the PFFile object first and then used it with PFObject

  if(succeeded)
  {
    PFObject *shout = [PFObject objectWithClassName:@"UserData"];
    shout[@"audioData"] = audiofile;
    [shout saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if(error)
        {
            NSLog(@"error %@",error.localizedDescription);

        }
        else
        {
            if(succeeded)
            {
                NSLog(@"object save on parse");
            }
        }
    }];
  }

}];

Upvotes: 0

Related Questions