//
// ViewController.m
// AFNetworkUpload
//
// Created by hq on 16/4/18.
// Copyright © 2016年 hanqing. All rights reserved.
//
#import "ViewController.h"
#import <AFNetworking.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
AFHTTPSessionManager *session=[AFHTTPSessionManager manager];
[session POST:@"http://120.25.226.186:32812/upload" parameters:@{@"username":@"123"} constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSURL *url=[NSURL fileURLWithPath:@"/Users/hq/Desktop/2.jpg"];
[formData appendPartWithFileURL:url name:@"file" fileName:@"2.jpg" mimeType:@"image/jpeg" error:nil];
} progress:^(NSProgress * _Nonnull uploadProgress) {
NSLog(@"%f",uploadProgress.fractionCompleted);
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"%@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
AFHTTPSessionManager 上传文件
最新推荐文章于 2024-09-18 15:13:56 发布
本文提供了一个使用AFNetworking库在iOS应用中实现文件上传功能的示例代码。通过AFHTTPSessionManager进行POST请求,并附带参数及文件上传进度的监控。
443

被折叠的 条评论
为什么被折叠?



