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(@"已上传");

        }

        

    }

  • 相关阅读:
    The Quad
    将OrCAD Capture CIS的设计文件(.dsn)导入到PADS Logic VX.2.3
    OrCAD Capture CIS 16.6 将版本16.6的设计文件另存为版本16.2的设计文件
    Eclipse IDE 添加jar包到Java工程中
    PADS Logic VX.2.3 修改软件界面语言
    切换Allegro PCB Editor
    Allegro PCB Design GXL (legacy) 将brd文件另存为低版本文件
    Allegro PCB Design GXL (legacy) 设置自动保存brd文件
    Could not create an acl object: Role '16'
    windows 下apache开启FastCGI
  • 原文地址:https://www.cnblogs.com/-ios/p/4669622.html
Copyright © 2011-2022 走看看