AFN做是最简单的。
NSURL *fileURL = [NSURL fileURLWithPath:zipPath];//zipPath是zip文件路径,是NSString类型的
NSURL *url = [NSURL URLWithString:@"http://..."];
AFHTTPSessionManager *client = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
client.responseSerializer = [AFJSONResponseSerializer serializer];
client.requestSerializer.timeoutInterval = 30.0f;
NSURLSessionDataTask *task = nil;
//如果有参数需要拼接到url上,可以在POST:写字符串
task = [client POST:nil parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSURL *url = fileURL;
NSError *error = nil;
[formData appendPartWithFileURL:url
name:@"file"
error:&error];
if (error) {
DGJLogError(@"uploadFileLog call appendPartWithFileURL error! Error is %@",error);
}
} progress:nil
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (responseObject) {
NSDictionary *dicContent = responseObject;
NSInteger status = [[dicContent objectForKey:@"status"] intValue];
if (status == 0 ) {
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error = %@",error);
}];