我只想在谷歌驱动器上上传视频,到目前为止,我可以使用 DrEdit for Objective-C / iOS 示例代码下载文本文件的内容以及所有文本文件的列表。它还给出了一个图片上传的例子,但这对我也没有帮助。因此,请大家分享您的想法或链接或代码片段,这将是可观的。提前致谢
问问题
1220 次
2 回答
0
只需点击此链接即可上传图片。
我只是编辑方法
(void)uploadPhoto:(UIImage*)image to -(void)uploadVideo: 图片上传示例
-(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!"]; } }]; }
于 2013-11-08T06:00:59.377 回答
0
这是一个使用 Swift 2.2 和 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)
}
}
}
于 2016-10-26T03:05:00.237 回答