【问题标题】:Google Drive (Docs) Import error: Images not shown in updated Docs filesGoogle 云端硬盘(文档)导入错误:图片未显示在更新的文档文件中
【发布时间】:2012-12-13 04:31:35
【问题描述】:

您好 Google Drive API 支持人员,

过去几天,我们在使用 Google 云端硬盘时遇到了严重问题。

我们无法再更新包含图像的 Docs 文档。当我们的 iPhone 应用发送一个更新 Docs 文档的图片请求时,服务器返回 OK,但里面的图片永远不会被上传。

重现问题的代码在这里。

- (void)selfOverwriteSelectedFile:(GTLDriveFile *)gtlDriveFile
{
    // -- not working type -- can't upload images on ODT, HTML, RTF, PDF
    NSString *mimetype = @"application/vnd.oasis.opendocument.text"; //@"text/html" @"application/rtf" @"application/pdf"

    //works: DOCX
    //NSString *mimetype = @"application/vnd.openxmlformats-officedocument.wordprocessingml.document";

    NSString *downloadUrl = [gtlDriveFile.exportLinks additionalPropertyForName:mimetype];

    //1st request: download the file
    GTMHTTPFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadUrl];

    [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
        //2nd request: re-upload the same file
        gtlDriveFile.mimeType = mimetype;
        GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:mimetype];
        GTLQueryDrive *query = [GTLQueryDrive queryForFilesUpdateWithObject:gtlDriveFile fileId:gtlDriveFile.identifier uploadParameters:uploadParameters];
        query.convert = query.newRevision = query.setModifiedDate = YES;

        [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *newGtlFile, NSError *error2nd) {
        }];
    }];
}

//replace the method for easy-test
-(void)duplicateSelectedFile
{
    GTLDriveFile *selectedFile = [self selectedFileListEntry];
    [self selfOverwriteSelectedFile:selectedFile];
}

为了最简单的复制,

  1. 下载最新的“Objective-C 的 Google APIs 客户端库”。
  2. 在 XCode 中打开 DriveSample 项目。
  3. 用代码替换“- (void)duplicateSelectedFile”方法。
  4. 编译并执行修改后的示例应用程序“获取文件列表”,选择包含图像的 docs 文件,然后点击“复制”。
  5. 应使用相同的内容覆盖所选文件。但是,里面的图片都丢失了(在无休止的等待上传状态)。

仅供参考,odt/html/rtf/pdf 导入不起作用。但是,docx 导入有效。

请尽快解决问题。

感谢您的支持。

【问题讨论】:

    标签: objective-c google-drive-api


    【解决方案1】:
     (void)loadFileContent {
    
        alert = [DrEditUtilities showLoadingMessageWithTitle:@"Loading file content"
                                                               delegate:self];
    
        self.webView.delegate = self;
    
        NSString *exportURLStr = nil;
        NSString *downloadUrlStr = nil;
    
        if (![self.driveFile.downloadUrl length] > 0) {
    
    
        if ([exportURLStr length] == 0) {
    
            exportURLStr = [self.driveFile.exportLinks JSONValueForKey:@"text/plain"];
    
        }
    
        if([exportURLStr length] == 0)
        {
    
            exportURLStr = [self.driveFile.exportLinks JSONValueForKey:@"image/jpeg"];
    
            self.webView.hidden= FALSE;
    
            NSString *imgHTMLTag = [NSString stringWithFormat:@"<img src=\"file://%@\" />", exportURLStr];
    
            if ([imgHTMLTag length] != 27)  {  // null
    
                [self.webView loadHTMLString:imgHTMLTag baseURL:nil];
                [alert dismissWithClickedButtonIndex:0 animated:YES];
                return;
    
            }
    
        }
    
        if([exportURLStr length] == 0)
        {
    
            exportURLStr = [self.driveFile.exportLinks JSONValueForKey:@"application/pdf"];
    
            self.webView.hidden= FALSE;
    
            NSURL *targetURL = [NSURL URLWithString:exportURLStr];
            NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
            [self.webView loadRequest:request];
            [alert dismissWithClickedButtonIndex:0 animated:YES];
            return;
    
        }
    
      if ([exportURLStr length] != 0) {
    
    
        GTMHTTPFetcher *fetcher =
      [self.driveService.fetcherService fetcherWithURLString:exportURLStr];
    
      [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
    
        [alert dismissWithClickedButtonIndex:0 animated:YES];
        if (error == nil) {
    
    
          NSString* fileContent = [[NSString alloc] initWithData:data
                                                        encoding:NSUTF8StringEncoding];
    
            self.webView.hidden = TRUE;
    
            self.textView.text = fileContent;
    
          self.originalContent = [fileContent copy];
    
        } else {
    
          NSLog(@"An error occurred: %@", error);
          [DrEditUtilities showErrorMessageWithTitle:@"Unable to load file"
                                             message:[error description]
                                            delegate:self];
    
        }
      }];
        }
    
        else
        {
    
             [alert dismissWithClickedButtonIndex:0 animated:YES];
    
        }
    
    
        }
    
        else
        {
    
            downloadUrlStr = self.driveFile.downloadUrl;
    
            NSLog(@"%@",downloadUrlStr);
    
            NSArray *arr = [downloadUrlStr componentsSeparatedByString:@"&"];
            urlString = [arr objectAtIndex:0];
    
            NSURL *url =[NSURL URLWithString:urlString];
            NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url];
    
            self.webView.hidden = FALSE;
            [self.webView loadRequest:urlRequest];
             [alert dismissWithClickedButtonIndex:0 animated:YES];
    
            [self performSelector:@selector(downloadFile) withObject:nil afterDelay:0.5];
            // [self downloadFile];
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-02
      相关资源
      最近更新 更多