首页 > Web开发 > 详细

AF上传图片问题

时间:2014-11-30 18:48:01      阅读:346      评论:0      收藏:0      [点我收藏+]

   前几天用AF作网络请求,在上传图片的时候遇到了一些问题。。

- (void)postRequsetUploadImage:(NSString *)url Dic:(NSDictionary *)dic image:(UIImage *)image
{
    
    NSString * strUrl = [HostAddress stringByAppendingString:url];

    appDelegate = [UIApplication sharedApplication].delegate;
    // 设置请求格式
    
    [appDelegate.manager POST:strUrl parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
       
        NSString *fileName = [NSString stringWithFormat:@"%@.png",[dic objectForKey:@"Realname"]];

        [formData appendPartWithFileData:UIImagePNGRepresentation(image) name:@"Data" fileName:fileName mimeType:@"image/png"];

    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

        if (_dataBlock) {
            _dataBlock(result,nil);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIAlertView * ar = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络错误,请检查网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [window addSubview:ar];
        [ar show];
        
        hub  =(MBProgressHUD *)[window viewWithTag:5000];
        if (hub) {
            
            [hub removeFromSuperview];
        }
        NSLog(@"出现错误: %@", error);
        
    }];
    
    
}

代码没有问题 ,但是在上传的时候,一直是未响应,网上查了很多,有很多人说是af2.0上传的类有点问题,导致不能上传。然后下载了很多,终于找到了一个。。

下载链接: http://download.csdn.net/detail/think_ma/8210275


AF上传图片问题

原文:http://blog.csdn.net/think_ma/article/details/41623965

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!