从Google Drive下载文件时下载进度状态? [英] Download Progress Status, when file is downloading from Google Drive?

查看:283
本文介绍了从Google Drive下载文件时下载进度状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从Google驱动器下载文件,但我想知道下载进度。任何人都可以告诉我如何做到这一点?



我已经试过这个下载文件:

  NSString * downloadURL = [[self.driveFiles objectAtIndex:indexPath.row] downloadUrl]; 
GTMHTTPFetcher * fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadURL];
filename = [[NSString alloc] init];
[fetcher beginFetchWithCompletionHandler:^(NSData * data,NSError * error)
{
GTLDriveFile * file = [driveFiles objectAtIndex:indexPath.row];
NSLog(@\\\
\\\
\\\
\\\
\\\
);
NSLog(@This is File Size =====>%@,file.fileSize);
NSLog(@这是文件名称===>%@,file.title);
$ b $ if(file.downloadUrl!= nil)
{
if(data!= nil)
{
filename = file.title;

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [[paths paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@%@,filename]];
[data writeToFile:documentsDirectory atomically:YES];


解决方案

编辑






我找到了一个更简单的解决方案。有一个块将用于进度的回调:

$ $ $ $ $ $ $ $ $ c $ gt; GTMHTTPFetcher * fetcher =
[self.driveService .fetcherService fetcherWithURLString:downloadURL];
GTLDriveFile * file = [driveFiles objectAtIndex:indexPath.row];

[fetcher setReceivedDataBlock:^(NSData * data){
NSLog(@%f %% Downloaded,(100.0 / [file.fileSize longLongValue] * [data length])) ;
}];


I am able to download files from Google drive, but I want to know the download progress. Can any one tell me how to do it?

I have tried this for downloading the files:

NSString *downloadURL = [[self.driveFiles objectAtIndex:indexPath.row] downloadUrl];
GTMHTTPFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadURL];
filename=[[NSString alloc] init];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
 {
     GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];
     NSLog(@"\n\n\n\n\n");
     NSLog(@"This is File Size=====>%@",file.fileSize);
     NSLog(@"This is file Name===>%@",file.title);

     if(file.downloadUrl!= nil)
     {
         if (data!=nil)
         {
             filename=file.title;

             NSArray *paths =    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
             NSString *documentsDirectory = [paths objectAtIndex:0];
             documentsDirectory = [[paths   objectAtIndex:0]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",filename]];
             [data writeToFile:documentsDirectory atomically:YES];

解决方案

Edit


I found a much simpler solution. There is a block that will be used for callbacks of the progress:

GTMHTTPFetcher *fetcher =
    [self.driveService.fetcherService fetcherWithURLString:downloadURL];
GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];

[fetcher setReceivedDataBlock:^(NSData *data) {
    NSLog(@"%f%% Downloaded", (100.0 / [file.fileSize longLongValue] * [data length]));
}];

这篇关于从Google Drive下载文件时下载进度状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆