zoukankan      html  css  js  c++  java
  • iOS 下载图片 -当后台返回的数据是文件流而不是图片url

     NSString *urlStr = [NSString stringWithFormat:@"%@uploadFileRest/downFile",[AFAppDotNetAPIClient getUrl]];

                        NSURL *url = [NSURL URLWithString:urlStr];

                        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

                        request.HTTPMethod = @"POST";

                        NSString *post = [NSString stringWithFormat:@"contentType=%@&fileName=%@&filePath=%@",model.CONTENT_TYPE,model.FILE_NAME,model.FILE_PATH];

                        request.HTTPBody = [post dataUsingEncoding:NSUTF8StringEncoding];

                        

                        NSURLSession *session = [NSURLSession sharedSession];

                        

                        // 可以不必创建请求直接用url进行获取,但是只能应用于get请求

                        

                        NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

                            if (error) {

                                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:error.localizedDescription preferredStyle: UIAlertControllerStyleAlert];

                                

                                UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {

                                }];

                                [alert addAction:okAction];

                                //弹出提示框;

                                [self presentViewController:alert animated:true completion:nil];

                            }else

                            {

                                image1 = [UIImage imageWithData:data];

                                dispatch_async(dispatch_get_main_queue(), ^

                                {

                                    // 更UI

                                    UIImageView *imgView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];

                                    //  imgView.backgroundColor = [UIColor yellowColor];

                                    imgView1.image = image1;

                                    [self.view addSubview:imgView1];

                               });

                            }

                        }];

                        [task resume];

  • 相关阅读:
    wrod2010删除分节符
    英文找工作网站
    win7中如何关闭“windows正在下载更新”
    设置pdf为护眼绿色
    如何查询Lancome生产及保质期
    (转)浅谈.NET下的多线程和并行计算(二)线程基本知识
    (转)浅谈.NET下的多线程和并行计算(一)前言
    (转载)一步一步学Linq to sql系列文章
    LINQ简介和LINQ to SQL语句之Where
    浅谈sql 、linq、lambda 查询语句的区别
  • 原文地址:https://www.cnblogs.com/amy54/p/5367788.html
Copyright © 2011-2022 走看看