介绍
今天就跟大家聊聊有关怎么在ios中使用AFN上传文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
安康;(void)上传{ NSData 才能;* imageData =, (NSData dataWithContentsOfFile: [[NSBundle mainBundle], pathForResource: @" mine.jpeg",减低:nil)]; NSDictionary *,才能URLParameters =, @{//设置请求头,}; NSURL 才能;* url =, (NSURL fileURLWithPath: [[NSBundle mainBundle], pathForResource: @" mine.jpeg",减低:nil)]; NSURLRequest 才能;* request =, (NSURLRequest requestWithURL: url); NSURLResponse 才能;* repsonse =,零; (才能NSURLConnection sendSynchronousRequest: request returningResponse:, repsonse 错误:nil); ,, NSString 才能;* mimeType =, repsonse.MIMEType; NSLog才能(@" % @",, repsonse.MIMEType); ,, ,,[[AFHTTPSessionManager 经理),职位:@"上传网址“,参数:URLParameters constructingBodyWithBlock: ^ (idmine.jpeg是在项目存在的图片,编译时会以NSBundle的形式存在。首先通过NSURLConnection同步发送请求获取MIMEType,然后使用AFN,可以将需要上传的imageData通过方法appendPartWithFileData:放在请求体中,然后传入已经获得的MIMEType,就能顺利实现上传了。
看完上述内容,你们对怎么在ios中使用AFN上传文件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。
怎么在ios中使用AFN上传文件