-(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);
    }];

    
}

 

相关文章:

  • 2022-02-07
  • 2021-11-24
  • 2021-11-30
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案