views:

29

answers:

1

Hi,

I am storing images data as blob data type on MySQL on server. Now I would like to retrieve images from that MySQL database to iPhone. But I don't know how I can do that, can somebody suggest me some solutions?

I can view the images using PHP script on server. But how I send image data to iPhone? In Iphone, I am using NSURLConnection to connect with PHP script.

Thanks.

A: 
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
 self.connection = nil;
 NSString * dataStr = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
 NSArray * lines = [dataStr componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

 NSMutableArray * res = [NSMutableArray arrayWithCapacity:[lines count]];
 NSString * line = nil;
 Picture * pic = nil;

 for (NSUInteger i = 0; i < [lines count]; i++) {
  line = (NSString*) [lines objectAtIndex:i];
  NSArray * arr = [line componentsSeparatedByString:@","];

  pic = [[Picture alloc] init];
  pic.pictureId = [[NSDecimalNumber decimalNumberWithString:(NSString *) [arr objectAtIndex:0]] intValue];
  pic.title = (NSString*) [arr objectAtIndex:1];
  pic.description = (NSString*) [arr objectAtIndex:2];
  pic.imageData = (NSData*) [arr objectAtIndex:3];
  pic.rate = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:4]] floatValue];
  pic.numberOfRate = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:5]] intValue];
  pic.numberOfDownload = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:6]] intValue];
  pic.numberOfComment = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:7]] intValue];
  [res addObject:pic];
  [pic release];
 }


 self.picturesData = res;


 //display a image
 [self displayAImage];
 [dataStr release];
}

I do this but dataStr returned nil, do you think I have problem with encoding?

haisergeant