I would like to save 2 datas in one PFFile : one image, and one data sound. That's right for the image (fileData), but I would like to add a column in Parse.com for the data sound (fileData2). How can I make this ? I can't do : "PFFile *file = [PFFile fileWithName:fileName data:fileData,fileData2];"
Here is my code :
- (void)uploadMessage {
NSData *fileData;
NSData *fileData2;
NSString *fileName;
NSString *fileType;
if (self.image != nil) {
[SVProgressHUD showWithStatus:@"Sending..." maskType:SVProgressHUDMaskTypeClear];
UIImage *newImage = [self resizeImage:self.image toWidth:320.0f andHeight:480.0f];
fileData = UIImagePNGRepresentation(newImage);
fileData2 = self.datasound;
fileName = @"image.png";
fileType = @"image";
}
PFFile *file = [PFFile fileWithName:fileName data:fileData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
message:@"Please try sending your message again."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[SVProgressHUD dismiss];
[alertView show];
}
else {
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] valueForKey:@"name"] forKey:@"senderName"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
message:@"Please try sending your message again."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[SVProgressHUD dismiss];
[alertView show];
}
else {
// Everything was successful!
[self reset];
[SVProgressHUD dismiss];
}
}];
}
}];
}
You can't (easily) put two files into one PFFFile. PFFFile is meant to represent one file.
Make two instances of PFFile, one for the image and one for the sound file.
PFFile *imageFile = [PFFile fileWithName:imageFileName data:imageFileData];
PFFile *soundFile = [PFFile fileWithName:soundFileName data:soundFileData];
The set those instances of PFFile to the respective parse columns. E.g.:
[message setObject:imageFile forKey:@"imageFile"];
[message setObject:soundFile forKey:@"soundFile];