0

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?

modusCell
  • 13,151
  • 9
  • 53
  • 80

2 Answers2

0

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");
            }
        }
    }];
  }

}];
Nimisha Patel
  • 406
  • 5
  • 13
  • Hi, thanks for your prompt response. I checked the file size, and it's only a couple 100 kb. In addition, the PFFile saves succesfully. But I still get the error. –  Aug 07 '14 at 19:06
  • I literally just copied and posed your response and it still fails. –  Aug 08 '14 at 02:39
  • @DavidJackson I am modified my code.Just check which error is generated in the inner block. – Nimisha Patel Aug 08 '14 at 06:10
  • and it throws error: Error: invalid type for key audioData, expected bytes, but got file (Code: 111, Version: 1.2.20) –  Aug 10 '14 at 18:48
  • what is even stranger is if i replace that line to: shout[@"audioData"] = @"test"; I get the error Error: invalid type for key audioData, expected bytes, but got string (Code: 111, Version: 1.2.20) WHAT IS going on here? I should be able to save strings in PFObjects, right? –  Aug 10 '14 at 19:01
  • @DavidJackson Error code 111 - "Field set to incorrect type." It is possible first you save another type of value in "audioData" field in previous row. And then you trying to save the PFFile in the same field.Try one option either delete all the records from the class "UserData" or create a new class on parse.Will you please put the screenshot of parse table ? – Nimisha Patel Aug 11 '14 at 06:06
  • I figured it out. The problem was I wasn't deleting the row in parse where the "audiodata" variable was stored. Even though all the "shouts" were deleted, Parse still remembers all the types of the shout class since I hadn't deleted the class. –  Aug 11 '14 at 20:15
0

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

Roman
  • 366
  • 5
  • 19