base64转码上传服务器

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];

    if ([user valueForKey:@"用户"]==nil) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有登录" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];

        [alert show];

        [alert dismissWithClickedButtonIndex:3 animated:YES];

    }else{

    //    NSLog(@"%@", info);

    

    // UIImagePickerControllerOriginalImage 原始图片

    // UIImagePickerControllerEditedImage 编辑后图片

    

    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

    // NetImageView *imageView = (NetImageView*)[self.view viewWithTag:300];

    // NSLog(@"%f,%f",image.size.width,image.size.height);

    

    [picker dismissViewControllerAnimated:YES completion:NULL];

    //存储头像

    NSData *data = nil;

    data = UIImageJPEGRepresentation(image, 0.00001);

    //base64转码

    NSString *pictureString=[data base64Encoding];

    // NSLog(@"pictureString==%@",pictureString);

    picType = @"jpg";

    //本地照片路径

    NSString *filePath = [NSString stringWithFormat:@"%@/Documents/",NSHomeDirectory()];

    filePath = [NSString stringWithFormat:@"%@%@.%@",filePath,@"HeadImage",picType];

    [data writeToFile:filePath atomically:YES];

    //NSLog(@"path+++++%@",filePath);

    //_headImage.mImageView.image = [UIImage imageWithContentsOfFile:filePath];

    //    self.iconImage.image = [UIImage imageWithContentsOfFile:filePath];

    //    NSData *da=UIImageJPEGRepresentation(self.iconImage.image, 0.1);

    

    mImageFilePath = filePath;

    _view1.image= [UIImage imageWithContentsOfFile:mImageFilePath];

    [self.tableView reloadData];

    

    //[self sendPersionInfo];

    

    if (self.mDownManager) {

        return;

    }

    //    [self StartLoading];

    //创建下载类

    self.mDownManager = [[ASIDownManager alloc] init];

    self.mDownManager.delegate = self;

    self.mDownManager.OnImageDown = @selector(OnLoadFinish:);

    self.mDownManager.OnImageFail = @selector(OnLoadFail:);

    

    

    __weak typeof(self) weakSelf=self;

    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];

    

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];

    NSString *str=[NSString stringWithFormat:@"http://服务器号userid=%@",[user valueForKey:@"用户"]];

    NSLog(@"用户%@",[user valueForKey:@"用户"]);

    

    NSURL *url = [NSURL URLWithString:str];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request setHTTPMethod:@"POST"];

    //NSLog(@"%@",pictureString);

    NSString *bodyStr = [NSString stringWithFormat:@"licence_imgid=%@",pictureString];

    bodyStr=[bodyStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [request setHTTPBody:[bodyStr dataUsingEncoding:NSUTF8StringEncoding]];

    

    //NSLog(@"********%@",bodyStr);

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

    

    NSOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"+++++%@",responseObject);

        if ([responseObject[@"code"]isEqualToString:@"100"]) {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提交成功" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

            alert.delegate=self;

            [alert show];

            

            [self.navigationController popViewControllerAnimated:YES];

            

        }else{

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提交失败" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

            alert.delegate=self;

            [alert show];

        }

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        

        //NSLog(@"Error: %@", error);

    }];

    [manager.operationQueue addOperation:operation];

    //    //修改成功 弹出对话框 并反悔上级页面

    //    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"上传成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    //    [alertView show];

    //    [self.navigationController popViewControllerAnimated:YES];

    //    NSLog(@"已上传");

    }

    

}

 

你可能感兴趣的:(base64)