答案 0 :(得分:0)
使用此功能将文件上传到驱动器并收听进度:
GTLServiceDrive *driveService = ...;
NSString *title = @"hello.txt";
NSString *content = @"Hello world";
NSString *mimeType = @"text/plain";
GTLDriveFile *metadata = [GTLDriveFile object];
metadata.title = title;
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:metadata
uploadParameters:uploadParameters];
GTLServiceTicket *uploadTicket = [driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error) {
if (error == nil) {
NSLog(@"File %@", updatedFile);
} else {
NSLog(@"An error occurred: %@", error);
}
}];
[uploadTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite)
{
// progress here
}];