七牛------iOS多文件上传demo

**//选择上传的内容,放到数组中**
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);
}];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值