//1single-image upload Afhttprequestoperationmanager*manager = [Afhttprequestoperationmanager manager]; [Manager post:urlstring Parameters:paramsconstructingbodywithblock:^(Id_nonnull formData) {//use date to generate picture nameNSDateFormatter*formatter =[[NSDateFormatter alloc] Init];formatter.dateformat=@"YYYY-MM-DD HH:mm:ss"; NSString*filename = [NSString stringWithFormat:@"%@.png", [Formatter stringfromdate:[nsdate Date]]; [FormData appendpartwithfiledata:imagedata Name:@"UploadFile"Filename:filename MimeType:@"Image/png"];} Success:^ (Afhttprequestoperation * _nonnull operation,ID_nonnull Responseobject) {//upload image successfully executed callbackcompletion (RESPONSEOBJECT,NIL);} Failure:^ (Afhttprequestoperation * _nonnull operation, Nserror *_nonnull Error) {//upload image failed to execute callbackcompletion (NIL,ERROR);}];2Multi-image upload multi-image upload and single-image upload difference is the file name Afhttprequestoperationmanager*manager = [Afhttprequestoperationmanager manager]; [Manager post:urlstring Parameters:paramsconstructingbodywithblock:^(Id_nonnull formData) {Nsinteger Imgcount=0; for(NSData *imagedatainchImagedatas) {NSDateFormatter*formatter =[[NSDateFormatter alloc] Init];formatter.dateformat=@"YYYY-MM-DD HH:mm:ss:SSS"; NSString*filename = [NSString stringWithFormat:@"%@%@.png", [Formatter stringfromdate:[nsdate date]],@ (Imgcount)]; [FormData appendpartwithfiledata:imagedata name:[nsstring stringWithFormat:@"uploadfile%@", @ (Imgcount)] Filename:filename MimeType:@"Image/png"];imgcount++;}} Success:^ (Afhttprequestoperation * _nonnull operation,ID_nonnull Responseobject) {completion (RESPONSEOBJECT,NIL);} Failure:^ (Afhttprequestoperation * _nonnull operation, Nserror *_nonnull Error) {completion (nil,error);}]; Text/spykerking (book author) original link: http://www.jianshu.com/p/0e28fdef0f91Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
02-ios using AFN for single and multi-image uploads