国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS實(shí)現(xiàn)壓縮圖片上傳功能

2020-07-26 03:21:31
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)壓縮圖片上傳功能,供大家參考,具體內(nèi)容如下

#pragma mark - 打開相機(jī)-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{  UIImage *image = info[UIImagePickerControllerOriginalImage];  self.currentTapCell.photoManageImgView.image = image;  NSIndexPath * indexPath = [self.baseTable indexPathForCell:self.currentTapCell];  NSString * key = [NSString stringWithFormat:@"ineed%u%u", indexPath.row, indexPath.section];    [[NetEngineHelper shareNetEngine] postUploadWithUrl:k_uploadPhoto_url image:image fileName:[NSString stringWithFormat:@"%@.png", key] fileType:@"PNG/JPEG/JPG" success:^(id response) {    if ([response[@"STATUS"] intValue] != 0) {      NSString * str = @"";      if (response[@"ERRORDESC"]) {        str = response[@"ERRORDESC"];      }else{        str = @"系統(tǒng)異常";      }      [AlertHelper shareAlertHelper].onVC = self;      [AlertHelper shareAlertHelper].alertTitle = str;      [AlertHelper shareAlertHelper].alertMessage = nil;      [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(id response) {               }];    }else{      [AlertHelper shareAlertHelper].onVC = self;      [AlertHelper shareAlertHelper].alertTitle = @"上傳成功";      [AlertHelper shareAlertHelper].alertMessage = nil;      [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(id response) {               }];             if ([self.currentTapCell.photoDescribeLable.text isEqualToString:@"上傳診斷證明"]) {        [self.successUploadDic setValue:response[@"FILEID"] forKey:@"PROVEID"];      }      if ([self.currentTapCell.photoDescribeLable.text isEqualToString:@"上傳病歷首頁"]){        [self.successUploadDic setValue:response[@"FILEID"] forKey:@"CASEHOMEID"];      }                           NSLog(@"上傳結(jié)果  %@", response);    }   } fail:^(NSError *error) {    [AlertHelper shareAlertHelper].onVC = self;    [AlertHelper shareAlertHelper].alertTitle = error.userInfo[@"NSLocalizedDescription"];    [AlertHelper shareAlertHelper].alertMessage = nil;    [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(id response) {           }];   }];        [self dismissViewControllerAnimated:YES completion:^{       }];}            #pragma mark - 打開相機(jī)-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{  UIImage *image = info[UIImagePickerControllerOriginalImage];  self.currentTapCell.photoManageImgView.image = image;  NSIndexPath * indexPath = [self.baseTable indexPathForCell:self.currentTapCell];  NSString * key = [NSString stringWithFormat:@"ineed%u%u", indexPath.row, indexPath.section];    [[NetEngineHelper shareNetEngine] postUploadWithUrl:k_uploadPhoto_url image:image fileName:[NSString stringWithFormat:@"%@.png", key] fileType:@"PNG/JPEG/JPG" success:^(id response) {    if ([response[@"STATUS"] intValue] != 0) {      NSString * str = @"";      if (response[@"ERRORDESC"]) {        str = response[@"ERRORDESC"];      }else{        str = @"系統(tǒng)異常";      }      [AlertHelper shareAlertHelper].onVC = self;      [AlertHelper shareAlertHelper].alertTitle = str;      [AlertHelper shareAlertHelper].alertMessage = nil;      [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(id response) {               }];    }else{      [AlertHelper shareAlertHelper].onVC = self;      [AlertHelper shareAlertHelper].alertTitle = @"上傳成功";      [AlertHelper shareAlertHelper].alertMessage = nil;      [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(id response) {               }];             if ([self.currentTapCell.photoDescribeLable.text isEqualToString:@"上傳診斷證明"]) {        [self.successUploadDic setValue:response[@"FILEID"] forKey:@"PROVEID"];      }      if ([self.currentTapCell.photoDescribeLable.text isEqualToString:@"上傳病歷首頁"]){        [self.successUploadDic setValue:response[@"FILEID"] forKey:@"CASEHOMEID"];      }                           NSLog(@"上傳結(jié)果  %@", response);    }   } fail:^(NSError *error) {    [AlertHelper shareAlertHelper].onVC = self;    [AlertHelper shareAlertHelper].alertTitle = error.userInfo[@"NSLocalizedDescription"];    [AlertHelper shareAlertHelper].alertMessage = nil;    [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(id response) {           }];   }];        [self dismissViewControllerAnimated:YES completion:^{       }];}             /**上傳文件*/-(void)postUploadWithUrl:(NSString *)urlStr image:(UIImage *)image fileName:(NSString *)fileName fileType:(NSString *)fileTye success:(Success)success fail:(Faile)fail{     NSString * resultStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];  self.success = success;  self.failer = fail;  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];  manager.responseSerializer = [AFHTTPResponseSerializer serializer];  manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",@"text/plain" ,nil];  [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];  manager.responseSerializer=[AFJSONResponseSerializer serializer];  manager.requestSerializer = [AFHTTPRequestSerializer serializer];  [manager.securityPolicy setAllowInvalidCertificates:YES];     UIApplication *application = [UIApplication sharedApplication];  application.networkActivityIndicatorVisible = YES;  [manager POST:resultStr parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {         NSData * imgData = UIImageJPEGRepresentation(image, 0.02);    [formData appendPartWithFileData:imgData name:@"FILENAME" fileName:fileName mimeType:fileTye];            } success:^(AFHTTPRequestOperation *operation, id responseObject) {    success(responseObject);    application.networkActivityIndicatorVisible = NO;  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {    fail(error);    application.networkActivityIndicatorVisible = NO;  }];}

以上就是本文的全部內(nèi)容,希望對(duì)大家學(xué)習(xí)iOS程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长阳| 青浦区| 饶阳县| 明星| 巨野县| 镇远县| 通化县| 贵南县| 河源市| 云浮市| 会泽县| 湖南省| 西青区| 迁安市| 确山县| 黄骅市| 昭平县| 南皮县| 涟源市| 麦盖提县| 郯城县| 武宣县| 西林县| 定结县| 镇宁| 北宁市| 宁安市| 龙江县| 慈溪市| 黔西| 陆河县| 石柱| 沁阳市| 霍林郭勒市| 永嘉县| 耒阳市| 唐河县| 东至县| 沭阳县| 新干县| 大田县|