0

我有一个 MySQL 数据库,其中包含我想下载到我的 iPhone 应用程序中的图像。图像存储为 BLOB。我有一个 PHP 脚本,它可以从数据库中抓取任何这些图像并将它们显示在网页上。为此,我使用:

$query  = "SELECT * FROM images WHERE imageName = '$nameOfImage'";
$result = mysql_query($query);
$image = mysql_fetch_array($result);

header('Content-type: ' . $image['mime_type']);
header('Content-length: ' . $image['file_size']);

echo $image['file_data'];

这工作得很好,到目前为止一切都很好。

但是如何将这些图像放入我的应用程序中?我以前在我的应用程序中成功解析过 XML - 但我正在解析文本数据。你如何用 BLOBS 做到这一点?我需要什么 PHP 代码来生成 XML,然后我可以解析以获取 BLOB 数据?有任何想法吗?

4

1 回答 1

1

如果您使用以下方式下载图像NSURLConnection

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    receivedData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [receivedData appendData:data];
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    UIImage *downloadedImage = [[UIImage alloc] initWithData:receivedData];
    // deal with it!
}

如果没有,你必须找到一个保存响应数据的属性(它可能被称为responseData),所以用它来初始化你的图像。

于 2012-06-09T21:21:28.787 回答