gpt4 book ai didi

IOS:如何使用 Google Drive SDK 库将文件上传到特定的 Google Drive 文件夹

转载 作者:可可西里 更新时间:2023-11-01 03:27:49 26 4
gpt4 key购买 nike

我将 Google Drive SDK 与我的 iOS 应用程序集成在一起。但我不知道如何将文件上传到 Google 驱动器特定文件夹。

此处的代码用于上传文件。但是这个将文件上传到我的谷歌驱动器根文件夹。任何人共享代码以将文件上传到谷歌驱动器特定文件夹?

我的代码:

-(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");
}
}];
}

最佳答案

您需要设置driveFile 引用的parents 属性。

GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
parentRef.identifier = folderIdentifier; // identifier property of the folder
driveFile.parents = @[ parentRef ];

关于IOS:如何使用 Google Drive SDK 库将文件上传到特定的 Google Drive 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13439457/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com