-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{Afhttpsessionmanager*manager =[Afhttpsessionmanager Manager]; [Manager POST:@"Http://localhost:8080/FileUpdateDemo/FileDemo"Parameters:nil constructingbodywithblock:^ (ID_nonnull FormData) {UIImage*image = [UIImage imagenamed:@"22.jpg"]; NSData*imagedata =uiimagepngrepresentation (image); //use Formdata to stitch data /*first parameter: Binary data file parameters to be uploaded the second parameter: The server specifies the third parameter: The file is uploaded to the server for what name to save*/[formData appendpartwithfiledata:imagedata name:@"file"FileName:@"Xxxx.png"MimeType:@"Image/png"]; //[FormData appendpartwithfileurl:[nsurl fileurlwithpath:@ "/users/zyyt/desktop/11.jpg"] name:@ "file" fileName:@ "123.png" mimetype:@ "Image/png" error:nil]; //[FormData appendpartwithfileurl:[nsurl fileurlwithpath:@ "/users/zyyt/desktop/11.jpg"] name:@ "file" Error:nil];} Progress:^ (Nsprogress *_nonnull uploadprogress) {NSLog (@"%f",1.0* uploadprogress.completedunitcount/uploadprogress.totalunitcount); } Success:^ (Nsurlsessiondatatask * _nonnull task,ID_nullable Responseobject) {NSLog (@"Upload Successful---%@", Responseobject); } Failure:^ (Nsurlsessiondatatask * _nullable task, Nserror *_nonnull Error) {NSLog (@"upload failed---%@", error); }]; }
iOS uploading images to Java backstage with AFN