I encapsulated a method that uses afnetworking to upload multiple graphs. With progress bar callback, I hope to help you, my app in the pro-test is available, do not know how your server receives data:
/** * Upload content with pictures, allow multiple images upload (URL) post** @param URL Network request address * @param images to upload an array of images (note that the array content needs to be a picture) * @param parameter The corresponding parameters of the image array (note multiple pictures, each picture name should be different) * @param parameters Other parameters dictionary * @param ratio Picture compression ratio (between 0.0~1.0) * @param succeedblock Successful callback * @param Failedblock failed callback * @param uploadprogressblock Callback for Progress*/+(void) Startmultipartuploadtaskwithurl: (NSString *) URL Imagesarray: (Nsarray*) Images parameterofimages: (NSString*) parameter parametersdict: (Nsdictionary*) Parameters Compressionratio: (float) ratio Succeedblock: (void(^) (IDOperation,IDresponseobject)) Succeedblock Failedblock: (void(^) (IDOperation, Nserror *error)) Failedblock Uploadprogressblock: (void(^) (floatUploadpercent,Long LongTotalbyteswritten,Long Longtotalbytesexpectedtowrite)) Uploadprogressblock; Achieve:+(void) Startmultipartuploadtaskwithurl: (NSString *) URL Imagesarray: (Nsarray*) Images parameterofimages: (NSString*) parameter parametersdict: (Nsdictionary*) Parameters Compressionratio: (float) ratio Succeedblock: (void(^) (ID,ID)) Succeedblock Failedblock: (void(^) (ID, Nserror *)) Failedblock Uploadprogressblock: (void(^) (float,Long Long,Long Long)) uploadprogressblock{if(Images.count = =0) {NSLog (@"uploaded content does not contain pictures"); return; } for(inti =0; i < Images.count; i++) { if(! [Images Iskindofclass:[uiimageclass]]) {NSLog (@"the%d element in images is not a UIImage object", i+1); return; }} afhttprequestoperation*operation = [[Self Sharedoperation].operationmanager post:url parameters:parameters constructingbodywithblock:^ (ID<AFMultipartFormData>formData) { inti =0; //generate picture names based on current system timeNSDate *date =[NSDate Date]; NSDateFormatter*formatter =[[NSDateFormatter alloc]init]; [Formatter Setdateformat:@"yyyy mm month DD Day"]; NSString*datestring =[Formatter stringfromdate:date]; for(UIImage *imageinchimages) {NSString*filename = [NSString stringWithFormat:@"%@%d.png", Datestring,i]; NSData*ImageData; if(ratio >0.0f&& ratio <1.0f) {ImageData=uiimagejpegrepresentation (image, ratio); }Else{imageData= UIImageJPEGRepresentation (Image,1.0f); } [FormData appendpartwithfiledata:imagedata name:parameter filename:filename mimeType:@"Image/jpg/png/jpeg"]; }} Success:^ (Afhttprequestoperation *operation,IDresponseobject) {Succeedblock (operation,responseobject); } Failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@"%@", error); Failedblock (Operation,error); }]; [Operation Setuploadprogressblock:^ (Nsuinteger Byteswritten,Long LongTotalbyteswritten,Long Longtotalbytesexpectedtowrite) {CGFloat percent= Totalbyteswritten *1.0/Totalbytesexpectedtowrite; Uploadprogressblock (Percent,totalbyteswritten,totalbytesexpectedtowrite); }]; }
IOS uploads multiple pictures at once and returns progress values