Tuesday, 13 August 2013

The File is not writing to the Document Directory?

The File is not writing to the Document Directory?

// I am trying to download file from google drive i am able to list file
in nslog with its size but not able to write in document Directory.
Currently It save a pathwith extension but not saving the original file.
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]];
[documentsDirectory writeToFile:documentsDirectory atomically:YES
encoding:NSUTF8StringEncoding error:nil];
NSLog(@"my path:%@",documentsDirectory);
}
else
{
NSLog(@"Error - %@", error.description);
}
}];

No comments:

Post a Comment