本文介绍了如何从谷歌驱动器部分下载文件使用目标c?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从谷歌驱动器使用目标下载一个大文件,并且使用google-api-objectivec-client-read-only lib.But当我下载大文件时,我看到了内存繁荣。
例如,文件的大小是589M,程序的内存大于600M。所以我想从谷歌驱动器部分下载文件。
我的代码:
I wanna download a big file from google drive use objective,and I use the google-api-objectivec-client-read-only lib.But when I download the big file,I see the memory boom up.For example,the file's size is 589M,the program's memory more than 600M.So I wannna partial download the file from google drive.My code:
-(void)getFileMetadataWithService:(NSString *)fileId
{
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:fileId];
[service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *file,
NSError *error) {
if (error == nil) {
NSLog(@"Title: %@", file.title);
NSLog(@"Description: %@", file.descriptionProperty);
NSLog(@"MIME type: %@", file.mimeType);
NSLog(@"download url:%@",file.downloadUrl);
NSLog(@"export link:%@",file.exportLinks);
[self downloadFileContentWithService:@"example"
file:file];
} else {
NSLog(@"An error occurred: %@", error);
}
}];
}
-(void)downloadFileContentWithService:(NSString *)loaclpath
file:(GTLDriveFile *)file
{
NSLog(@"download file");
if (file.downloadUrl != nil)
{
NSLog(@"begin download");
GTMHTTPFetcher *fetcher =[service.fetcherService fetcherWithURLString:file.downloadUrl];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
[data writeToFile:@"/Users/mycomputer/Desktop/a.mov" atomically:YES];
[data writeToFile:@"/Users/mycomputer/Desktop/b.mov" atomically:YES];
[data writeToFile:@"/Users/mycomputer/Desktop/c.mov" atomically:YES];
NSLog(@"download ok");
} else {
NSLog(@"An error occurred: %@", error);
}
}];
}
else
{
}
}
如何修改从谷歌驱动器部分下载文件的方法?
How to modify the method to partial download a file from google drive?
推荐答案
修理它,它很容易。
我将代码修改为:
OK,I fix it up.It is so easy.I modify the code as:
-(void)downloadFileContentWithService:(NSString *)loaclpath
file:(GTLDriveFile *)file
{
NSLog(@"download file");
if (file.downloadUrl != nil)
{
NSLog(@"begin download");
GTMHTTPFetcher *fetcher =[service.fetcherService fetcherWithURLString:file.downloadUrl];
fetcher.downloadPath = @"/Users/KarlDoenitz/Desktop/download/bisaishipin.mov";
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(@"download ok");
} else {
NSLog(@"An error occurred: %@", error);
}
}];
}
else
{
}
}
这篇关于如何从谷歌驱动器部分下载文件使用目标c?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!