GTMSessionfetcher google drive UPLOAD to Google drive Objective C?

时间:2017-04-16 11:47:32

标签: ios objective-c google-drive-api

根据发布的here文件,我可以使用GTMSessionFetcher下载和上传。 在文档表单中,我还有一些链接,我有一个代码,用于授权下载表格google Drive:

GTLRQuery *query = [GTLRDriveQuery_FilesGet queryForMediaWithFileId:fileID];
NSURLRequest *downloadRequest = [service requestForQuery:query];
GTMSessionFetcher *fetcher =
  [service.fetcherService fetcherWithRequest:downloadRequest];

[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *fetchError) {
  if (fetchError == nil) {
    // Download succeeded.
  }
}];

一切正常!

我的问题是:如何将GTMSessionFetcher上传到iOS中的Google云端硬盘?

1 个答案:

答案 0 :(得分:0)

尝试Google Toolbox for Mac - Session Fetcher中的此代码:

@interface GTMSessionUploadFetcher : GTMSessionFetcher

// Create an upload fetcher specifying either the request or the resume location URL,
// then set an upload data source using one of these:
//
//   setUploadFileURL:
//   setUploadDataLength:provider:
//   setUploadFileHandle:
//   setUploadData:

+ (instancetype)uploadFetcherWithRequest:(NSURLRequest *)request
                          uploadMIMEType:(NSString *)uploadMIMEType
                               chunkSize:(int64_t)chunkSize
                          fetcherService:(GTM_NULLABLE GTMSessionFetcherService *)fetcherServiceOrNil;

+ (instancetype)uploadFetcherWithLocation:(NSURL * GTM_NULLABLE_TYPE)uploadLocationURL
                           uploadMIMEType:(NSString *)uploadMIMEType
                                chunkSize:(int64_t)chunkSize
                           fetcherService:(GTM_NULLABLE GTMSessionFetcherService *)fetcherServiceOrNil;

- (void)setUploadDataLength:(int64_t)fullLength
                   provider:(GTM_NULLABLE GTMSessionUploadFetcherDataProvider)block;

github代码声明 GTMSessionFetcher 使Cocoa应用程序可以轻松执行http操作。 fetcher是作为 NSURLSession 的包装器实现的,因此它的行为是异步的,并且在iOS和Mac OS X上使用操作系统设置。

希望这有帮助。