I have client iOS app, which should send json request to server with audio bytes.
On server I have Hibernate (MySQL) with next model:
@Column(name = "voice_data", nullable = false, unique = false, columnDefinition="mediumblob")
@Lob
public byte[] getVoiceData() { return voiceData; }
public void setVoiceData(byte[] voiceData) { this.voiceData = voiceData; }
At iOS I want to get just recorded voice and save to DB:
@property (strong, nonatomic) AVAudioRecorder *audioRecorder;
// some code ...
NSData *data = [[NSData alloc] initWithContentsOfFile:_audioRecorder.url.path];
NSString* dataAsString = [NSString stringWithUTF8String:[data bytes]];
NSDictionary *params = @{
MODEL_VOICE_VOICE_DATA : dataAsString,
// etc parameters
};
NSString *url = [NSString stringWithFormat:@"%@", URL];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:url parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// ...
}
];
}
//
Then on server I have input request data:
[{"id":13,"voiceData":[],"date":....
So, looks like it's not correctly parsing from Audio (as it's empty). What I do wrong? And how I should send data to server?