2

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 am trying GTMHTTPFetcher to download..but getting error

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
GTLDriveFile *file;
NSString *downloadedString = file.downloadUrl; // file is GTLDriveFile

NSLog(@"%@",file.downloadUrl);

GTMHTTPFetcher *fetcher = [self.driveService.fetcherService  fetcherWithURLString:downloadedString];

[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
{
    if (error == nil)
    {
        if(data != nil)
        {

            GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];

            filename=file.title;

            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);


        }
    }
    else
    {
        NSLog(@"Error - %@", error.description);
    }
 }];


// from the above code error is **Domain=com.google.GTMHTTPFetcher Code=-1 "The operation couldn’t be completed. (com.google.GTMHTTPFetcher error -1.)"**
NextStep
  • 429
  • 5
  • 20
  • What's the content of the file? Don't you use an authentification of some kind to access this file? – ldiqual Aug 08 '13 at 06:57
  • The content of file is audio, size is 3 MB..i already authenticated and listed files in table view..from there i m downloading.. – NextStep Aug 08 '13 at 06:59
  • is it failing ? did you check - (void)connection:(NSURLConnection *)aConn didFailWithError:(NSError *)error ? – zahreelay Aug 08 '13 at 07:03
  • @zahreelay... i m not getting any kind of error....i have used this method – NextStep Aug 08 '13 at 07:06
  • @LoïsDiQual ...i am trying to download 50 kb file than also it showing 80 kb what is the issue – NextStep Aug 08 '13 at 12:40
  • @JamesRyan ...check -(void)connectionDidFinishLoading:(NSURLConnection*)connection...method – ChenSmile Aug 08 '13 at 13:43
  • @zahreelay...what is the issue.... – NextStep Aug 08 '13 at 14:15
  • I would look at the downloaded file in a dumb text editor or similar to see if its 82kB of audio data, or just some complicated link/text/error thing. Google Docs files 'download' as a url. – Tom Andersen Aug 08 '13 at 23:33
  • Can you please tell me how did you authenticate the access to file? – vburojevic Aug 10 '13 at 09:51
  • @TomAndersen What is the issue...why file is not downloading properly..even 1o kb file shows 82 kb... – NextStep Aug 12 '13 at 04:53
  • @zahreelay issue is that file is downloading but when it is downloaded it shows 82 kb...all downloaded files are 82 kb ...if u can resolve..plz help – NextStep Aug 12 '13 at 04:55
  • @zahreelay .are u there – NextStep Aug 12 '13 at 06:43
  • @Wikiboo If i am able to list all files in table means they are authenticated... – NextStep Aug 12 '13 at 09:02
  • don't use your own method, Google provided `GTMHTTPFetcher` to download the file. – TheTiger Aug 12 '13 at 09:14
  • http://stackoverflow.com/questions/17995787/listing-all-folder-content-from-google-drive/18009616#18009616 – TheTiger Aug 12 '13 at 09:18
  • Can you check this answer http://stackoverflow.com/questions/4002979/downloading-a-large-file-iphone-sdk – zahreelay Aug 12 '13 at 09:29
  • @JamesRyan, Yes I know, but how do you get direct link to download the file? From what I understand, the only way to download files from google drive is by using GTMHTTPFetcher. webContentLink is not a direct link to file, neither is property downloadUrl, that is why you cannot download the file. I am also trying to solve this problem. I want to download the file by using its direct link and my own methods. – vburojevic Aug 12 '13 at 09:37
  • @Wikiboo how can i use this method.. i m trying but getting Domain=com.google.GTMHTTPFetcher Code=-1 "The operation couldn’t be completed. (com.google.GTMHTTPFetcher error -1.)" – NextStep Aug 12 '13 at 09:49
  • Please show the code where you are using GTMHTTPFetcher – vburojevic Aug 12 '13 at 09:51
  • @Wikiboo now check the modified code – NextStep Aug 12 '13 at 10:11
  • @Wikiboo .. i m getting null value.... – NextStep Aug 12 '13 at 10:33
  • @TheTiger i m getting NULL value.... NSLog(@"%@",file.downloadUrl); – NextStep Aug 12 '13 at 11:43

3 Answers3

2

I don't have a solution, but I have a diagnosis, and the next step. If multiple files, some long, some short, are fetching 82KB, then double check that you are fetching the correct URL.

It looks like, when the user chooses a filename you aren't fetching the correct URL, but something returning 82KB of data, like the directory listing.

You can check by running the DrEdit sample app from https://developers.google.com/drive/examples/objectivec and by turning on GMHTTPFetcher logging, (GMHTTPFetcher is a wrapper for NSURLConnection) http://code.google.com/p/gtm-http-fetcher/wiki/GTMHTTPFetcherIntroduction#HTTP_Logging

DavidPhillipOster
  • 4,195
  • 1
  • 19
  • 17
  • Hi ... i have checked it.. but if u can elaborate ur answer how can i use the GTMFHTTPFetcher in Download Method it will be useful.. I hope u understand my issue.... Thanks – NextStep Aug 12 '13 at 04:38
1

i think u r giving time out interval thats why its finishes loading at fix time.

anand madhav
  • 353
  • 4
  • 10
0

The method downloadFormatSelected: in the [DriveSample sample app][1] shows how to do an authenticated file download.

grobbins
  • 1,564
  • 1
  • 8
  • 6
  • When i am Importing DriveSampleview file in my project i m getting error that cocoa file not found...if u explain how it can be possible it will be much better...thanks – NextStep Aug 12 '13 at 04:52