Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
chitra iyer
3,722 PointsInvalid type for key fileType, expected bytes, but got string
Hi,
I am trying to display my messages in the InboxViewController but I get a runtime error because the fileType is null. On checking the data browser on Parse it seems the fileType is not getting saved when I send the messages in the CameraViewController. The error that i get in the debugger is - "Invalid type for key fileType, expected bytes, but got string " i.e. the variable fileType which is NSString cannot be saved using the message setObject forKey method of PFObject. I did not find any notes in the bottom of the video. Is it something to do with the new version of xcode? I am really stuck here and though I have a workaround for now, I want to know whats happening :(
Thanks!
7 Answers
chitra iyer
3,722 PointsPFObject *message = [PFObject objectWithClassName:@"Messages"];
[message setObject:file forKey:@"file"];
[message setObject:fileType forKey:@"fileType"];
[message setObject:self.recipients forKey:@"recipientIds"];
[message setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
[message setObject:[[PFUser currentUser] username] forKey:@"senderName"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
}
Its exactly from the video....:)
chitra iyer
3,722 Pointsobjective-c
PFObject *message = [PFObject objectWithClassName:@"Messages"];
[message setObject:file forKey:@"file"];
[message setObject:fileType forKey:@"fileType"];
[message setObject:self.recipients forKey:@"recipientIds"];
[message setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
[message setObject:[[PFUser currentUser] username] forKey:@"senderName"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
Stone Preston
42,016 Pointscan you post the code where you set the file type variable thats used in this line?
[message setObject:fileType forKey:@"fileType"];
where did you set that fileType variable?
Stone Preston
42,016 PointsMake sure for your fileType variable you declared it as NSString *fileType and not PFFile *fileType
chitra iyer
3,722 PointsIt is NSString. I double checked!
NSString *fileType;
if(self.image != nil){
UIImage *newImage = [self resizeImage:self.image toWidth:128.0f andHeight:128.0f];
fileData = UIImagePNGRepresentation(newImage);
fileName = @"image.png";
fileType = @"image";
}else{
fileData = [NSData dataWithContentsOfFile:self.videoFilePath];
fileName = @"video.mov";
fileType = @"video";
}
chitra iyer
3,722 PointsIs it something to do with the Parse API? The workaround was to drop the class from the data browser and again run it. That worked! No change in code!
Stone Preston
42,016 Pointshmm thats interesting. well glad its working then
chitra iyer
3,722 Pointsyes, but I was wondering why it happened in the first place :(
Stone Preston
42,016 PointsStone Preston
42,016 Pointscan you post your code where you set the value of the file type?