标签:lock pat data update event pen named code gre
-(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); //使用formData来拼接数据 /* 第一个参数:二进制数据 要上传的文件参数 第二个参数:服务器规定的 第三个参数:该文件上传到服务器以什么名称保存 */ [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(@"上传成功---%@",responseObject); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"上传失败---%@",error); }]; }
标签:lock pat data update event pen named code gre
原文地址:http://www.cnblogs.com/jianbo-su/p/6251723.html