dry18813 2012-04-04 10:04
浏览 1284

在iOS上从网页请求BLOB

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!

  • 写回答

1条回答

  • douren5490 2012-04-04 11:22
    关注

    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];
             });
         }); 
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘