**//选择上传的内容,放到数组中**
NSString *file1 = [[[NSBundle mainBundle]pathForResource:@"picture" ofType:@"bundle"] stringByAppendingPathComponent:@"0b11711cf955d77e44764558e3ef235e.png"];
NSString *file2 = [[[NSBundle mainBundle]pathForResource:@"picture" ofType:@"bundle"] stringByAppendingPathComponent:@"0b11711cf955d77e44764558e3ef235e.png"];
NSString *file3 = [[[NSBundle mainBundle]pathForResource:@"picture" ofType:@"bundle"] stringByAppendingPathComponent:@"0b11711cf955d77e44764558e3ef235e.png"];
NSArray *ary = @[file1,file2,file3];
**//该链接公网不可访问**
AFHTTPRequestOperationManager *manger = [AFHTTPRequestOperationManager manager];
NSString *url = @"http://zhanghan/qiniu/examples/up.php";
manger.responseSerializer = [AFHTTPResponseSerializer serializer];
[manger GET:url parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
**//获取token**
NSString *token = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
QNUploadManager *manager = [[QNUploadManager alloc]init];
**//开启异步线程上传图片**
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < ary.count; i++) {
**//图片转为data类型**
UIImage *image = [UIImage imageNamed:[ary objectAtIndex:i]];
NSData *data = UIImageJPEGRepresentation(image, 0);
**//上传**
[manager putData:data key:nil token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
if (info.statusCode == 200) {
NSLog(@"上传成功");
NSLog(@"%@",resp);
}else {
NSLog(@"上传失败");
NSLog(@"%@",info);
}
} option:nil];
}
});
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
**//失败**
NSLog(@"%@",error);
}];
}