iOS 압축 이미지 업로드 기능 구현
#pragma mark -
-(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 = @" ";
}
[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(@" %@", 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 -
-(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 = @" ";
}
[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(@" %@", 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;
}];
}
이상 은 본 고의 모든 내용 입 니 다.iOS 프로 그래 밍 을 배 우 는 데 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
View의 레이아웃 방법을 AutoLayout에서 따뜻한 손 계산으로 하면 성능이 9.26배로 된 이야기이 기사는 의 15 일째 기사입니다. 어제는 에서 이었습니다. 손 계산을 권하는 의도는 없고, 특수한 상황하에서 계측한 내용입니다 화면 높이의 10 배 정도의 contentView가있는 UIScrollView 레이아...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.