在iOS上从网页请求BLOB

我有一个存储在MySQL数据库中的BLOB图像,我想在我的iOS应用程序中使用它。 我已经创建了一个PHP文件来从数据库中检索BLOB,但我不确定我需要做什么才能将BLOB导入我的应用程序。</ p>

请你给我举个例子 ,或者指出我这样做的方向?</ p>

先谢谢!</ p>
</ div>

展开原文

原文

I have a BLOB image stored in a MySQL database, of which I would like to use in my iOS Application. I have created a PHP file to retrieve the BLOB from the database, but I am unsure of what I need to do to get the BLOB into my app.

Please can you give me an example, or point me in the direction of doing so?

Thanks in advanced!

doushenjia8514
doushenjia8514 我已经为用户编辑了问题和标题,希望它现在应该更容易理解。
8 年多之前 回复
duanpo2037
duanpo2037 对不起,也许我没有解释好我,我正在开发一个Iphone应用程序。是的,我想在ObjectiveC中检索图像
8 年多之前 回复
dongyingming8970
dongyingming8970 我认为你的问题不清楚。您是否在询问如何在Objective-C中检索图像?Xcode是IDE,Objective-C是语言。您是否尝试在Mac或iOS应用中使用此图像?
8 年多之前 回复

1个回答



使用 ASIIHTTPRequest </ a>从该PHP页面请求BLOB数据。</ p>

使用BLOB数据,将其转换为UIImage。</ p>

   - (  void)getBlobData:(NSURL *)url {
NSURL * url = [NSURL URLWithString:url];
__block ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url];
[请求setCompletionBlock:^ {
NSData * blobData = [request responseData];
UIImage * blobImage = [UIImage imageWithData:blobData] retain];
[someImageView performSelectorOnMainThread:@selector(setImage :))
withObject:blobImage
waitUntilDone:YES];
}];

[请求setFailedBlock:^ {
NSError * error = [request error];
}];
[请求startAsynchronous];
}
</ code> </ pre>

或者,您可以使用Grand Central Dispatch(GCD)向网页发送请求以接收blob:</ p>

   - (void)ge  tBlobData:(NSURL *)url {

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0ul);

dispatch_async(queue,^ {
NSData * blobData = [NSData dataWithContentsOfURL:url];
UIImage * blobImage = [UIImage imageWithData:blobData];
dispatch_sync(dispatch_get_main_queue(),^ {
[someImageView setImage: blobImage];
});
});

}
</ code> </ pre>
</ div>

展开原文

原文

Use ASIIHTTPRequest to request the BLOB data from that PHP page.

With the BLOB data, convert it to a UIImage.

- (void) getBlobData:(NSURL *) url {
    NSURL *url = [NSURL URLWithString:url];
    __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setCompletionBlock:^{
       NSData *blobData = [request responseData];
       UIImage *blobImage = [UIImage imageWithData:blobData] retain];
       [someImageView performSelectorOnMainThread:@selector(setImage:)
       withObject:blobImage 
       waitUntilDone:YES];
    }];

    [request setFailedBlock:^{
      NSError *error = [request error];
    }];
    [request startAsynchronous];
}

Alternatively, you could use Grand Central Dispatch (GCD) to send a request to the web-page in order to receive the blob:

- (void) getBlobData:(NSURL *) url {

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul); 
    dispatch_async(queue, ^{  
        NSData *blobData = [NSData dataWithContentsOfURL:url];       
        UIImage *blobImage = [UIImage imageWithData:blobData];
        dispatch_sync(dispatch_get_main_queue(), ^{
             [someImageView setImage:blobImage];
         });
     }); 
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐