iOS上传图片 base64数据上传

这个是从相册获取到图片并且在相对应的界面上显示选中的图片然后在上传到服务器的方法 当然还有其他的方法 

base64上传图片:

NSData *imageData = UIImageJPEGRepresentation(self.imageview.image, 0.6);

NSString *dataStr = [imageData base64EncodedStringWithOptions:0];

AFHTTPSessionManager * manager =[AFHTTPSessionManager manager];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/xml"];

manager.requestSerializer = [AFHTTPRequestSerializer serializer];

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

//参数

NSDictionary *parameters = @{@"timage" : dataStr,@"turl":self.self.newpassword.text,@"aid":self.aid,@"state":self.state,@"carrousel":self.carrousel};

[manager POST:@"http://192.168.1.135:8080/miaotuiapp/addTop.do" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

NSLog(@"success");

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

NSLog(@"~~~~~~~~%@",error);

}];

你可能感兴趣的:(iOS上传图片 base64数据上传)