如何上传谷歌驱动器上的图片(错误“GTMHTTPUploadFetcher connectionDidFinishLoading中的声明失败”) [英] how to upload an image on google drive(error "Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading")

查看:167
本文介绍了如何上传谷歌驱动器上的图片(错误“GTMHTTPUploadFetcher connectionDidFinishLoading中的声明失败”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在iOS应用中使用Google云端硬盘。我尝试上传文件,出现以下错误:

  ***断言失败 -  [GTMHTTPUploadFetcher connectionDidFinishLoading:], 

/ Users / mac / Desktop / google-api-objectivec-client-mirror-master / Source /

  NSAssert([[self downloadeddata] length] == 0,
@意外的响应数据(上传到错误的URL?));

将图片上传到Google Drive:

  - (void)uploadPhoto 
{
NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@'Quickstart Uploaded File('EEEE MMMM d,YYYY h:mm a,zzz')];
GTLDriveFile *文件= [GTLDriveFile对象];
file.title = [dateFormat stringFromDate:[NSDate date]];
file.descriptionProperty = @从Google Drive iOS Quickstart上传;
file.mimeType = @image / png;

UIImage * img = [UIImage imageNamed:@Default.png];
NSData * data = UIImagePNGRepresentation(img);

GTLUploadParameters * uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive * query = [GTLQueryDrive queryForFilesInsertWithObject:file $ b $ uploadParameters:uploadParameters];
UIAlertView * waitIndicator = [self showWaitIndicator:@上传到Google Drive];

[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket * ticket,GTLDriveFile * insertedFile,NSError * error)
{
[waitIndicator dismissWithClickedButtonIndex:0 animated :是];
if(error == nil)
{
NSLog(@File ID:%@,insertedFile.identifier);
[self showAlert:@Google Drivemessage:@File saved!];
}
else
{
NSLog(@An error occurred:%@,error);
[self showAlert:@Google Drivemessage:@Sorry,an error occurred!];
}
}];


解决方案

试试这个,



我修正了GTMHTTPUploadFetcher connectionDidFinishLoading中的声明失败)错误,遗憾的是我忘记启用
创建应用程序

创建应用程序



2.转到服务,打开Drive API。



您需要从API控制台/服务启用Drive API和Drive SDK标签


I'm trying to use Google Drive in my iOS app. I try to upload a file, I get the following error:

*** Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:], 

/Users/mac/Desktop/google-api-objectivec-client-mirror-master/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399

Here is the code that is highlighted when the assertion occurs:

NSAssert([[self downloadedData] length] == 0,
                @"unexpected response data (uploading to the wrong URL?)");

upload image to google drive:

- (void)uploadPhoto
{
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 = @"image/png";

UIImage   *img =[UIImage imageNamed:@"Default.png"];
NSData *data = UIImagePNGRepresentation(img);

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!"];
     }
 }];
  }

解决方案

Try this,

I rectified Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading") error unfortunately i forget to enable Google API Console Drive API

1.Create an App.

2.Go to Services, switch ON the "Drive API".

You need to enable Drive API and Drive SDK from the API Console/Services tab

这篇关于如何上传谷歌驱动器上的图片(错误“GTMHTTPUploadFetcher connectionDidFinishLoading中的声明失败”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆