I integrated google drivs sdk with my ios app. At present am using the following code to download the files from my google drive a/c based on download url link. But when i try to download the google docs files (which has mime type application/vnd.google-apps.document) there is no download url link from google drive library. In that case how can i download the google docs data?. Can i use alternateLink instead of download url link?. Any help must be appreciated.
My Code:
- (void)loadFileContent {
GTMHTTPFetcher *fetcher =
[self.driveService.fetcherService fetcherWithURLString:[[self.driveFiles objectAtIndex:selectedFileIdx] downloadUrl]];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(@"\nfile %@ downloaded successfully from google drive", [[self.driveFiles objectAtIndex:selectedFileIdx] originalFilename]);
//saving the downloaded data into temporary location
} else {
NSLog(@"An error occurred: %@", error);
}
}];
}
I had similar problem before. Specifically, I did not find downloadurl for the native documents created in Google Document. They are null. Only those created through DrEdit (solutions exemplified in Drive SDK) are associated with downloadUrl.
The solution is actually embedded in the attribute: JSON in GTLDriveFileExportLinks instance, which returns NSMutableDictionary*. You can choose to view the content of JSON object via access JSONString attribute. The JSON mutatable dictionary can be obtained through querying exportLinks in GTLDriveFile instance. The example is as below:
Here the steps to download the file from google drive. It will work for both file and also google docs.
Step 1:
Fetch the file list and store it into an array or dict with related file download link url:
}
step-2: add the file metadata info
step-3: download the file based on file select on the table row
Documents in Google Docs native formats can't be downloaded as other files, but only exported to different supported formats using the
exportLinks
URLs.For more details and the list of supported formats check the Google Drive SDK documentation:
https://developers.google.com/drive/manage-downloads#downloading_google_documents