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];

时间: 2024-08-05 02:59:50

iOS 下载图片 -当后台返回的数据是文件流而不是图片url的相关文章

application/x-www-form-urlencoded multipart/form-data text/plain 后台返回的数据响应的格式类型

application/x-www-form-urlencoded multipart/form-data text/plain 为什么上传文件的表单里要加个属性 enctype  后台返回的数据响应的格式类型 上传文件的表单中<form>要加属性enctype="multipart/form-data",很多人只是死记硬背知道上传表单要这么 写,知其然而不知其所以然.那到底为什么要添加这个属性呢?它是什么意思呢?它又有什么其他可选值呢? 其实form表单在你不写encty

javascript 对后台返回的数据进行分类

模拟后台返回的数据为: var arr = [ {personName:"张三",id:1,age:12,gender:"male"}, {personName:"张三",id:1,age:12,gender:"male"}, {personName:"张三",id:1,age:12,gender:"male"}, {personName:"李四",id:1,age:

iOS 如何加载后台返回的HTML数据

返回数据: <p><b>\U516c\U53f8\U7b80\U4ecb</b></p><p>    \U5584\U76c8\U7ba1\U7406\U56e2\U961f\U521b\U59cb\U4e8e2008\U5e74\Uff0c\U7ecf\U8fc7\U591a\U5e74\U7684\U5386\U7ec3\U73b0\U5df2\U53d1\U5c55\U6210\U4e3a\U4e00\U5bb6\U4ee5\U6295\U

vue项目 下载表格 java后台返回的是信息流表格如何下载解决乱码

主要是在请求参数后面加上{responseType: 'blob'}this.$http.get(this.api.export, { params: this.info, responseType: 'blob'}).then(res => { let blob = new Blob([res.data], {type: "application/vnd.ms-excel"}); let objectUrl = URL.createObjectURL(blob); window

根据后台返回的数据写一个分页,通用

// pageIndex ------> 当前页数,也就是页码了 const pageIndex = 1; // pageSize ------> 这是自定义每页需要展示的条数 const pageSize = 20; // roundfirmList ------> 这是获取后台返回的总的数据 var roundfirmList = res.data.body; // tpages ------> 这是获取后台返回的总页数,tCount const tpages = res.da

ionic后台返回的数据是html模板的时候,解析html文件的方法:

1.后台返回来的数据格式是: { "state":"100", "data":[ {"Content": "\u003c!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"\u003e\

SpringMVC返回JSON数据以及文件上传、过滤静态资源

返回JSON数据 在如今前后端分离的趋势下,后端基本不需要再去关心前端页面的事情,只需要把数据处理好并通过相应的接口返回数据给前端即可.在SpringMVC中,我们可以通过@ResponseBody注解来返回JSON数据或者是XML数据. 这个注解的作用是将控制器方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,也就是HTTP响应的内容体,一般我们都是用来返回JSON数据,因为默认是按JSON格式进行转换的. 需要注意的是,在使用此注解之后不会再走视图解

android上传图片并附带上传数据,文件流

关于android的图片上传有两种方式,一种是以文件流的方式上传,图片转换成二进制上穿.另一种是把图片转成base64方式上传,这篇博客我只介绍文件流,关于base64方式会在下一篇博客中介绍! 首先是安卓端:图片上传我们需要一个图片的路径,同过调用本地相册或者拍照可以返回图片路径,这个在这里就不说了:假设我们获得图片路径为PicPath; 下面是安卓代码: 首先我们要封装要发送的数据 数据封装好了以后用String path=URLEncodedUtils.format(Parameters,

springmvc,通过ajax方式提交页面数据,后台返回json数据中文信息乱码

本人刚开始接触springmvc,项目搭建参照https://my.oschina.net/gaussik/blog/385697.在用IDEA写登录注册的时候,想通过ajax方式提交数据到后台,然后遇到如题所述的乱码问题,然后度娘了好多,终于解决了.废话不多说,直接上代码. 首先是登录页面login.jsp 1 <%-- 2 Created by IntelliJ IDEA. 3 User: PENG027 4 Date: 2016/11/11 5 Time: 15:48 6 To chang