02-ios using AFN for single and multi-image uploads

Source: Internet
Author: User

//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

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.