// 我正在尝试从谷歌驱动器下载文件我能够在 nslog 中列出文件及其大小,但无法写入文档目录。目前它保存带有扩展名的路径但不保存原始文件。
GTLDriveFile *file;
NSString *downloadedString = file.downloadUrl; // file is GTLDriveFile
GTMHTTPFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadedString];
filename=[[NSString alloc]init];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
{
GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];
filename = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"\n\n\n\n\n");
NSLog(@"This is File Size=====>%@",file.fileSize);
NSLog(@"This is file Name===>%@",file.title);
if(file.downloadUrl!= 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 encoding:NSUTF8StringEncoding error:nil];
NSLog(@"my path:%@",documentsDirectory);
}
else
{
NSLog(@"Error - %@", error.description);
}
}];
// ya i got it...
NSString *downloadURL=[[self.driveFiles objectAtIndex:indexPath.row] downloadUrl];
GTMHTTPFetcher *fetcher =
[self.driveService.fetcherService fetcherWithURLString:downloadURL];