I have a BackendlessFile type property in my Objective-C class. When saving the object after uploading a file to backendless server, I get the error: Unable to save object - invalid data type for properties.
Following is my Objective-C class’s .h file code:
#import <Foundation/Foundation.h>
#import <BackendlessFile.h>
@interface detection_history : NSObject
@property (nonatomic, assign, getter = getObjectId, setter = setObjectId:) NSString *objectId;
@property (nonatomic, strong) NSDate *created;
@property (nonatomic, strong) NSDate *updated;
@property (nonatomic,strong)BackendlessFile *scream_file;
@property (nonatomic,strong)NSString *userObjectId;
@property (nonatomic,strong)NSString *userEmail;
@property (nonatomic,strong)NSString *device_type;
@property (nonatomic,strong)NSString *phone;
@property (nonatomic,strong)NSString *postcode;
@property (nonatomic,strong)NSString *fullname;
@property (nonatomic,strong)NSString *location;
@property (nonatomic,strong)NSString *address;
@end
Following is the file uploading and then saving ‘detection_history’ objective-C code:
The exact error I get is: Unable to save object - invalid data type for properties - scream_file. You can change the property type in developer console.
- (void) saveHistoryOnBackendless:(NSString*)p_strFilePath {
NSData *data = [[NSFileManager defaultManager] contentsAtPath:p_strFilePath];
NSString *fileName = [NSString stringWithFormat:@"screams/%0.0f.wav",[[NSDate date] timeIntervalSince1970] ];
NSLog(@"sending request for saving scream file upload");
[backendless.fileService upload:fileName content:data response:^(BackendlessFile *fileReturned) {
BackendlessUser *user = backendless.userService.currentUser;
detection_history *history = [detection_history new];
history.scream_file = fileReturned;
history.userObjectId = user.objectId;
history.userEmail = user.email;
history.device_type = @"iOS";
if([user getProperty:@"phone"]!=nil){
history.phone = [user getProperty:@"phone"];
}
if([user getProperty:@"postcode"]!=nil){
history.postcode = [user getProperty:@"postcode"];
}
NSString *strFullName = [NSString stringWithFormat:@"%@ %@", [user getProperty:@"first_name"], [user getProperty:@"last_name"]];
history.fullname = strFullName;
double dLatitude = 0;
double dLongitude = 0;
CLLocation* location = [[EMGLocationManager sharedInstance] m_location_gps];
if (location != nil) {
dLatitude = location.coordinate.latitude;
dLongitude = location.coordinate.longitude;
}
NSString *strLocation = [NSString stringWithFormat:@"(%.4f, %.4f)", dLatitude, dLongitude];
history.location = strLocation;
id<IDataStore> dataStore = [backendless.persistenceService of:[detection_history class]];
[dataStore save:history response:^(id response) {
NSLog(@"history saved");
} error:^(Fault * error) {
NSLog(@"detection history couldn't be saved: %@",[error message]);
}];
} error:^(Fault *error) {
NSLog(@"File couldn't be uploaded: %@",[error message]);
}];
}
Attached is the snapshot of detection_history table schema in backendless.