0

七牛上传图片,获取进度只有一次1.00。

  1. 上传时设置的代码

- (void)putData:(NSData *)filedata key:(NSString *)key progressHandler:(QNUpProgressHandler)progress complete:(QNUpCompletionHandler)completionHandler
{
    
    if (![self chechoutToken]) {
        [self getTokenWith:_param];
        return;
    }
    
    QNUploadOption *opt = [[QNUploadOption alloc] initWithMime:@"image/jpeg"
                                               progressHandler:progress
                                                        params:nil
                                                      checkCrc:false
                                            cancellationSignal:nil];
    
    QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
        NSMutableArray *array = [[NSMutableArray alloc] init];
        [array addObject:[QNResolver systemResolver]];
        QNDnsManager *dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];
        //是否选择  https  上传
        builder.zone = [[QNAutoZone alloc] initWithHttps:YES dns:dns];
        //设置断点续传
        NSError *error;
        builder.recorder = [QNFileRecorder fileRecorderWithFolder:@"保存目录" error:&error];
    }];
    
    QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:config];
    [upManager putData:filedata key:key token:_token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        if (completionHandler) {
            completionHandler(info, key, resp);
        }
    } option:opt];
}

执行时的代码

__weak typeof(self)weakself = self;
    [[EHQiNiuManager shareInstance] putData:data key:[NSString createFileNameWithPre:@"feedback"] progressHandler:^(NSString *key, float percent) {
        NSLog(@"%@: %.2f", key, percent);
        [UIView animateWithDuration:0.1 animations:^{
            weakself.coverView.frame = CGRectMake(0, 0, weakself.bounds.size.width, weakself.bounds.size.height * (1 - percent));
        }];
    } complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        if (resp == nil) {
            // 上传失败
            NSLogErrorLogin(@"上传失败:%@", info.error);
        } else {
            weakself.imageName = resp[@"key"];
        }
    }];

1 个回答

0

您好,上传的如果是小于4M的文件,不会启用分片上传,所以上传成功后返回进度1