views:

49

answers:

0

Hi Im trying to fetch an image from a blob field in a database and trying to insert into a UIWebView. thus far the code is

-(void)prepareHTML{
 imageBlob = [fp fetchImage:storyRowID]; //*****fetches the image blob data. returns an NSData*
 if([imageBlob length] <= 0){//****if there is no image data fetch it from the url and update row in db with blob data
  imageBlob = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[itemData objectAtIndex:0] objectAtIndex:3]]];
  [fp insertImage:imageBlob forRowID: storyRowID];
 }
 NSMutableString* string =[[NSMutableString alloc]init;    //***prepare string with html
    [string appendString:
  @"<html>"
  "<head>"
  "<meta name=\"viewport\" content=\"width=320\"/>"
  "</head>"
  "<body style='padding:3px;'>"];
[string appendString:[NSString stringWithFormat:@"<div style='font-weight:bold; font-size:large;' >%@</div>",[[itemData objectAtIndex:0] objectAtIndex:1]]]; 
    [string appendString:@"<div>"];
  NSString *imgStr = [[NSString alloc] initWithData:imageBlob encoding:NSUTF8StringEncoding];
    [string appendString:[NSString stringWithFormat:@"<img src=\"data:image/jpg;base64,%@\" alt=\"\"/>",imgStr]];//****INSERT IMAGE DATA
    [string appendString:@"</div>"];
    [string appendString:[NSString stringWithFormat:@"<br><br><div>%@</div>",[[itemData objectAtIndex:0] objectAtIndex:2]]];
    [string appendString:@"</body>"
     "</html>"
     ];
 [storyViewPage loadHTMLString:string baseURL:nil];
 [string release];
}

But this dosent work. What am I doing wrong? The images are being saved just fine because they show up in a UIImageView.