我是后端新手。我一直在与一个新后端开发人员合作的应用程序。我正在工作的一个应用程序,其中用户销售/购买产品。我可以发送产品的图像,从设备相机和通过POST方法发送到数据库。
拍摄的图像存储在数据库中。我的问题如下:
为了让这个图像返回到应用程序需要使用什么方法?在JSON中获取数据块或图像URL更好吗?
我建议获取图像URL,然后使用以下代码加载图像:
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL:url];
if (data == nil) {
NSLog(@"Uh oh! Couldn't retrieve the image");
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithData:data];
//do something with the image such as:
UIImageView *myImageView.image = image;
});
});