The xxxxxxxxxx in the text is more of your own parameter fill
-(void) Uploadimagewithimage: (nsstring *) ImagePath
{
//upload other required parameters
nsstring *userid=xxxxxxxxxxx;
nsstring *token=xxxxxxxxxxx;
//upload request post
afhttpclient *client=[afhttpclientclientwithbaseurl: [Nsurl urlwithstring: @ ""];
nsstring *urlstring=[nsstringstringwithformat:@ "Upload server address" ;
nsdictionary *dic=[[nsdictionaryalloc] initwithobjectsandkeys: userId,@ " XXXXXX ", token,@" XXXXXX ",Nil];
nsurlrequest *request = [Clientmultipartformrequestwithmethod:@ "POST" Path: urlstring parameters:d ICconstructingbodywithblock: ^ (ID < Afmultipartformdata > FormData) {
//Get the data you need to upload
nsdata *data=[nsdatadatawithcontentsoffile: ImagePath];
//upload using the current system event as file name
nsdateformatter *formatter = [[nsdateformatteralloc] init ];
Formatter. DateFormat =@ "YYYYMMDDHHMMSS";
nsstring *str = [Formatter stringfromdate: [nsdate date]];
nsstring *filename = [nsstringstringwithformat:@ "%@.jpg", str];
/*
This method parameter
1. [Binary data] to upload
2. [Field ' file '] for processing files [upload.php] on the website
3. [FileName] to save on the server
4. Uploading the file [MimeType]
*/
fields and types of server upload files
[formData appendpartwithfiledata:d ata name:@ "XXXXX"fileName: FileName mimeType:@ "Image/jpg/file"];
}];
//3. Operation Packaging of Urlconnetion
afhttprequestoperation *op = [[afhttprequestoperationalloc] Initwithrequest: request];
[Opsetcompletionblockwithsuccess: ^ (afhttprequestoperation *operation,ID Responseobject) {
NSLog (@ "upload complete");
}Failure: ^ (afhttprequestoperation *operation,nserror *error) {
NSLog (@ "Upload failed->%@", error);
}];
//Execute
[Client. Operationqueue addoperation: op];
}
Afnetworking Frame _ upload file or picture to server