通过IOS应用程序在Google云端硬盘上上传视频

时间:2013-11-08 04:35:19

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

我只想在google驱动器上传视频,到目前为止我可以使用DrEdit下载Objective-C / iOS示例代码的文本文件内容以及所有文本文件的列表。 它还提供了图像上传的示例,但这对我没有帮助。所以,你们可以分享你的想法或链接或代码片段,这将是可观的。提前谢谢

2 个答案:

答案 0 :(得分:0)

  

只需点击此链接即可上传图片。

我只是编辑方法

  • (void)uploadPhoto:(UIImage *)image to - (void)uploadVideo: image upload sample

      -(void)uploadVideo{
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"];
    
     GTLDriveFile *file = [GTLDriveFile object];
      file.title = [dateFormat stringFromDate:[NSDate date]];
      file.descriptionProperty = @"Uploaded from the Google Drive iOS Quickstart";
      file.mimeType = @"video/quicktime";
      NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"Mov"];
    
      NSError *error = nil;
       NSData *data = [NSData dataWithContentsOfFile:filePath options:nil error:&error];
    // NSData *data = UIImagePNGRepresentation((UIImage *)image);
       GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
        GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
                                                   uploadParameters:uploadParameters];
    
      UIAlertView *waitIndicator = [self showWaitIndicator:@"Uploading to Google Drive"];
    
       [self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket,
                                  GTLDriveFile *insertedFile, NSError *error) {
                  [waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
                  if (error == nil)
                  {
                      NSLog(@"File ID: %@", insertedFile.identifier);
                      [self showAlert:@"Google Drive" message:@"File saved!"];
                  }
                  else
                  {
                      NSLog(@"An error occurred: %@", error);
                      [self showAlert:@"Google Drive" message:@"Sorry, an error occurred!"];
                  }
              }];
    
    
    }
    

答案 1 :(得分:0)

这是一个使用Swift 2.2& amp;的简单实现。 Google API 3上传视频。

您只需提供视频所在位置的路径即可。或者,您可以使用URL替换它,并在函数中保存一个步骤。

func uploadVideo(videoPath: String) {
    let file = GTLDriveFile()
    file.name = "video.mov"
    file.descriptionProperty = "Video description"
    file.mimeType = "video/quicktime"

    let videoURL = NSURL(fileURLWithPath: videoPath)
    let uploadParameters = GTLUploadParameters(fileURL: videoURL, MIMEType: file.mimeType)
    let query = GTLQueryDrive.queryForFilesCreateWithObject(file, uploadParameters: uploadParameters)

    service.executeQuery(query) { (ticket, insertedObject, error) in
        if error == nil {
            print(ticket)
        } else {
            print(error.localizedDescription)
        }
    }
}