Wednesday, 7 August 2013

Only 82 kb 0f 3 MB is downloading from Google Drive?

Only 82 kb 0f 3 MB is downloading from Google Drive?

Hi I am downloading a media file of 3 MB from Google Drive. The file
finish downloading after 82 kb.. it is not downloading completely. I have
checked with small file.. but the download size remains constant for any
size of file.. that is 82 kb..
I have tried this to download my file from Google Drive......
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
GTLDriveFile *aObj=[self.driveFiles objectAtIndex:indexPath.row];
fileNames = [aObj title];
targetURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[aObj
webContentLink]]];
NSLog(@"%@",targetURL);
NSURLRequest* DownloadRequest = [NSURLRequest requestWithURL:targetURL
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:50.0];
NSURLConnection* DownloadConnection = [[NSURLConnection alloc]
initWithRequest:DownloadRequest delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData
*)data {
[receivedData appendData:data];
unsigned char byteBuffer[[receivedData length]];
[receivedData getBytes:byteBuffer];
NSLog(@"Data === %@",receivedData);
NSInteger receivedLen = [data length];
bytesReceived = (bytesReceived + receivedLen);
NSLog(@"received Bytes == %lld",bytesReceived);
if(expectedBytes != NSURLResponseUnknownLength)
{
NSLog(@"Expected Bytes in if == %lld",expectedBytes);
NSLog(@"received Bytes in if == %lld",bytesReceived);
float value = ((float) (bytesReceived *100/expectedBytes))/100;
NSLog(@"Value == %f",value);
}
}
-(void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response
{
expectedBytes = [response expectedContentLength];
NSLog(@"%lld",expectedBytes);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
filename = [[paths
objectAtIndex:0]stringByAppendingPathComponent:[NSString
stringWithFormat:@"%@",fileNames]];
NSData* Data = [[NSData alloc]initWithContentsOfURL:targetURL];
[Data writeToFile:filename atomically:YES];
NSLog(@"my path:%@",filename);
}
// from the above code only 82 kb of file is downloading in document
directory from table view, in Table view files belongs to Google Drive.

No comments:

Post a Comment