我正在iOS 8中开发应用程序,并且通过安装以下Pod集成了Google云端硬盘:
pod platform :ios, '8.0'
pod 'GoogleAPIClient/Drive', '~> 1.0.0'
pod 'GTMOAuth2', '~> 1.1.0'
当我放置代码以上传PDF文件时,出现以下错误:
这是我的代码:
GTLDriveFile *driveFile = [GTLDriveFile object];
driveFile.mimeType = @"application/pdf";
driveFile.originalFilename = @"database.pdf";
driveFile.name = @"database.pdf";
driveFile.size = fileSizeNumber;
NSString *parentId = @"root";
driveFile.parents = @[parentId];
NSData *fileContent = [[NSData alloc] initWithContentsOfFile:fileName];
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:fileContent MIMEType:@"application/pdf"];
GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
parentRef.identifier = folderIdentifier; // identifier property of the folder
driveFile.parents = @[ parentRef ];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:driveFile uploadParameters:uploadParameters];
[self.service 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.name
代替driveFile.title
GTLDriveParentReference
类,因此删除这些行。 queryForFilesCreateWithObject
代替queryForFilesInsertWithObject