IOS implementation compression image upload function _ios

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.