This article for everyone to share the image of iOS to achieve compression upload function for your reference, the specific content as follows
#pragma mark-Open camera-(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 = @ "System exception";
[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 = @ "Upload success";
[Alerthelper sharealerthelper].alertmessage = nil; [[Alerthelper Sharealerthelper] alertvcwithsureaction:^ (ID response)
{
}]; if ([Self.currentTapCell.photoDescribeLable.text isequaltostring:@ "Upload diagnostic certificate"]) {[Self.successuploaddic setvalue:res
ponse[@ "Fileid"] forkey:@ "Proveid"]; } if ([Self.currentTapCell.photoDescribeLable.text isequaltostring:@ "upload medical records first"]) {[Self.successuploaddic Setva
lue:response[@ "Fileid"] forkey:@ "Casehomeid"];
} NSLog (@ "Upload results%@", 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-Open camera-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediaw
Ithinfo: (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 = @ "System exception";
[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 = @ "Upload success";
[Alerthelper sharealerthelper].alertmessage = nil; [[Alerthelper Sharealerthelper] alertvcwithsureaction:^ (ID response)
{
}]; if ([Self.currentTapCell.photoDescribeLable.text isequaltostring:@ "Upload diagnostic certificate"]) {[Self.successuploaddic setvalue:res
ponse[@ "Fileid"] forkey:@ "Proveid"]; } if ([Self.currentTapCell.photoDescribeLable.text isequaltostring:@ "upload medical records first"]) {[Self.successuploaddic Setva
lue:response[@ "Fileid"] forkey:@ "Casehomeid"];
} NSLog (@ "Upload results%@", 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:^{}]; /** Upload file */-(void) Postuploadwithurl: (NSString *) URLSTR Image: (UIImage *) image fileName: (NSString *) filen Ame FileType: (NSString *) Filetye success: (Success) Success fail: (Faile) fail{NSString * resultstr = [Urlstr Stringbya
Ddingpercentencodingwithallowedcharacters:[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;
}];
}
The above is the entire content of this article, I hope to learn about the iOS program to help.