I integrated Google drive sdk with my iOS app. But I do not know how to upload a file to Google drive specific folder.
Here the code am using to upload the file. Bu
I don't know iOS, so may be off base, but does this code from https://developers.google.com/drive/v2/reference/files/insert help
+ (void)insertFileWithService:(GTLServiceDrive *)service
title:(NSString *)title
description:(NSString *)description
parentId:(NSString *)parentId
mimeType:(NSString *)mimeType
data:(NSData *)data
completionBlock:(void (^)(GTLDriveFile *, NSError *))completionBlock {
GTLDriveFile *file = [GTLDriveFile object];
file.title = title;
file.descriptionProperty = description;
file.mimeType = mimeType;
GTLUploadParameters *uploadParameters =
[GTLUploadParameters uploadParametersWithData:data MIMEType:mimeType];
GTLQueryDrive *query =
[GTLQueryDrive queryForFilesInsertWithObject:file
uploadParameters:uploadParameters];
You need to set the parents
property of your driveFile
reference.
GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
parentRef.identifier = folderIdentifier; // identifier property of the folder
driveFile.parents = @[ parentRef ];
GTLServiceTicket *_editFileListTicket;
GTLServiceDrive *service = self.driveService;
GTLDriveFile *folderObj = [GTLDriveFile object];
folderObj.title = [NSString stringWithFormat:@"%@", title];
folderObj.mimeType = @"application/vnd.google-apps.folder";
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:folderObj
uploadParameters:nil];
_editFileListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *folderItem,
NSError *error) {
if (error == nil)
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:nil message:@"Created" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else
{
NSLog(@"error");
}
}];