I am trying to send a blob data from oracle db to objective c via webservices. The blob data is a word document stored in oracle db.
Following is what I did so far:
- Obtain the blob object through java jdbc
- Convert the blob object into java byte array
- Setting this byte array in a plain java object (serialized) and sending it to the web service
- Webservice sends the plain java object to objective-c with Media-type as application/json
- The json object is retrieved in the objective-c and the byte array is assigned to NSData
- NSData is then written to a file and the file is opened
Problem: I am unable to open the file through objective-c and when I open the file physically in the mac it contains some junk characters. Can anyone please let me know if there is anyway that a java byte array which represents a word document could be converted to a objective-c recognized data type and finally open the word document in the objective-c app.
Following is the code for your perusal on the objective-c end:
Note: "sourceDoc" in the code is the key for byte array.
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if ([data length] >0 && error == nil){
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSData *returnData = nil;
for(NSDictionary *billDict in jsonArray){
returnData = [NSData dataWithBytes:(__bridge const void *)([billDict objectForKey:@"sourceDoc"]) length:[[billDict objectForKey:@"sourceDoc"] length]];
break;
}
}