GTMSessionfetcher google 驱动器上传到 Google 驱动器 Objective-C?
GTMSessionfetcher google drive UPLOAD to Google drive Objective-C?
根据发布的文档here,我可以使用 GTMSessionFetcher 下载和上传。
在 link 的文档表格中更进一步,我有一个授权下载表格的代码 google 驱动器:
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?
试试来自 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 [=28] 上使用操作系统设置=]X.
希望对您有所帮助。
根据发布的文档here,我可以使用 GTMSessionFetcher 下载和上传。 在 link 的文档表格中更进一步,我有一个授权下载表格的代码 google 驱动器:
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?
试试来自 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 [=28] 上使用操作系统设置=]X.
希望对您有所帮助。