IOS: How to upload a file to specific Google drive folder using Google drive sdk library

后端 未结 3 860
青春惊慌失措
青春惊慌失措 2020-12-31 19:51

I integrated Google drive sdk with my iOS app. But I do not know how to upload a file to Google drive specific folder.

Here the code am using to upload the file. Bu

相关标签:
3条回答
  • 2020-12-31 20:24

    I don't know iOS, so may be off base, but does this code from https://developers.google.com/drive/v2/reference/files/insert help

    + (void)insertFileWithService:(GTLServiceDrive *)service
                            title:(NSString *)title
                      description:(NSString *)description
                         parentId:(NSString *)parentId
                         mimeType:(NSString *)mimeType
                             data:(NSData *)data
                  completionBlock:(void (^)(GTLDriveFile *, NSError *))completionBlock {
      GTLDriveFile *file = [GTLDriveFile object];
    
      file.title = title;
      file.descriptionProperty = description;
      file.mimeType = mimeType;
    
      GTLUploadParameters *uploadParameters =
        [GTLUploadParameters uploadParametersWithData:data MIMEType:mimeType];
      GTLQueryDrive *query =
        [GTLQueryDrive queryForFilesInsertWithObject:file
                                    uploadParameters:uploadParameters];
    
    0 讨论(0)
  • 2020-12-31 20:28

    You need to set the parents property of your driveFile reference.

    GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
    parentRef.identifier = folderIdentifier; // identifier property of the folder
    driveFile.parents = @[ parentRef ];
    
    0 讨论(0)
  • 2020-12-31 20:49

    GTLServiceTicket *_editFileListTicket;

        GTLServiceDrive *service = self.driveService;
    
        GTLDriveFile *folderObj = [GTLDriveFile object];
    
        folderObj.title = [NSString stringWithFormat:@"%@", title];
    
        folderObj.mimeType = @"application/vnd.google-apps.folder";
    
        GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:folderObj
                                                           uploadParameters:nil];
        _editFileListTicket = [service executeQuery:query
                                  completionHandler:^(GTLServiceTicket *ticket,
                                                      GTLDriveFile *folderItem,
                                                      NSError *error) {
    
                                     if (error == nil)
                                     {
    
                                         UIAlertView *alert=[[UIAlertView alloc] initWithTitle:nil message:@"Created" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                                         [alert show];
    
    
                                        }
                                     else
                                     {
    
                                         NSLog(@"error");
    
                                      }
                                  }];
    
    0 讨论(0)
提交回复
热议问题