本文介绍了IOS:如何使用Google驱动器sdk库将文件上传到特定的Google驱动器文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Google驱动器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 $ b $ uploadParametersWithData:[NSData dataWithContentsOfFile:filePath]
MIMEType:@application / pdf];

GTLQueryDrive * query = [GTLQueryDrive queryForFilesInsertWithObject:driveFile $ b $ uploadParameters:uploadParameters];

[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket * ticket,
GTLDriveFile * updatedFile,
NSError * error){
if(错误==无){
NSLog(@\\\
\\\
file上传到谷歌驱动器\\< my_folder> foler);
} else {
NSLog(@\\\
\\\
file uplod failed google drive \\< my_folder> foler);
}
}];


解决方案

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

  GTLDriveParentReference * parentRef = [GTLDriveParentReference object]; 
parentRef.identifier = folderIdentifier; //文件夹的标识符属性
driveFile.parents = @ [parentRef];


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");
    }
}];
}
解决方案

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

这篇关于IOS:如何使用Google驱动器sdk库将文件上传到特定的Google驱动器文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 12:26