zoukankan      html  css  js  c++  java
  • 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(@"已上传");

        }

        

    }

  • 相关阅读:
    揭秘数字行为:快速地多次点击
    MySQL事务在MGR中的漫游记—路线图
    如何成为一名获客专家?
    10分钟快速构建汽车零售看板
    聊一聊整车厂的那些事——售后配件业务
    网易云易盾牵手百视通 助力广电领域新媒体内容安全
    人工智能热门图书(深度学习、TensorFlow)免费送!
    dubbo异步调用原理 (1)
    dubbo事件通知机制 (2)
    dubbo事件通知机制(1)
  • 原文地址:https://www.cnblogs.com/-ios/p/4669622.html
Copyright © 2011-2022 走看看