1

根据此处发布的文档,我可以使用 GTMSessionFetcher 进行下载和上传。在文档表单中更进一步的链接我有一个授权下载表单谷歌驱动器的代码:

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

它工作正常!

我的问题是:如何在 iOS 中使用 GTMSessionFetcher 上传到 Google Drive?

4

1 回答 1

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 上的操作系统设置。

希望这可以帮助。

于 2017-04-16T22:24:07.683 回答