1

According to the documents published here, I can download and upload with GTMSessionFetcher. And little bit further in the Documentation form the link I have a code for authorized download form 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.
  }
}];

It works fine!

My question is: how do I upload with GTMSessionFetcher to Google Drive in iOS?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Try this code from 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;

The github code states that GTMSessionFetcher makes it easy for Cocoa applications to perform http operations. The fetcher is implemented as a wrapper on NSURLSession, so its behavior is asynchronous and uses operating-system settings on iOS and Mac OS X.

Hope this helps.

Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91