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. But this one uploading the file to my google drive root folder. Any one share a code to upload a file to google drive specific folder?.
My Code:
-(void)uploadFileToGoogleDrive:(NSString*)fileName
{
GTLDriveFile *driveFile = [[[GTLDriveFile alloc]init] autorelease];
driveFile.mimeType = @"application/pdf";
driveFile.originalFilename = @"test.doc";
driveFile.title = @"test.doc";
NSString *filePath = [LocalFilesDetails getUserDocumentFullPathForFileName:fileName isSignedDocument:YES];
GTLUploadParameters *uploadParameters = [GTLUploadParameters
uploadParametersWithData:[NSData dataWithContentsOfFile:filePath]
MIMEType:@"application/pdf"];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:driveFile
uploadParameters:uploadParameters];
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error) {
if (error == nil) {
NSLog(@"\n\nfile uploaded into google drive\\<my_folder> foler");
} else {
NSLog(@"\n\nfile uplod failed google drive\\<my_folder> foler");
}
}];
}
When you upload a file to Google Drive, it will take up space in your Drive, even if you upload to a folder owned by someone else. Tap Add . Tap Upload. Find and tap the files you want to upload. If you want to upload files like Microsoft Word documents, you can change a setting to convert files.
Open the Settings app on your iPhone and select the Mobile Data menu. 2. There tap on Mobile Data Options. 3. On the next page, disable the toggle next to Low Data Mode. Now, you can upload to Google Drive using mobile data. On iPhone, when 20% battery is left, the phone asks you to enable the Low Power mode.
Sign up for a Google Workspace trial at no charge. You can upload, view, share, and edit files with Google Drive. When you upload a file to Google Drive, it will take up space in your Drive, even if you upload to a folder owned by someone else. Tap Add . Tap Upload. Find and tap the files you want to upload.
The ability to add files to Google Drive shared folders depends on your permission level. As an Owner, you can do anything in that folder. If someone else has shared a folder with you, you will either have View, Comment, or Edit access. In such cases, you can only upload files to that folder if you have Edit privileges.
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 ];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With