2012-12-13 67 views
6

nhân viên hỗ trợ API Hi Google Drive,Google Drive (Documents) Import lỗi: Hình ảnh không hiển thị trong Documents cập nhật tập tin

Trong vài ngày qua, chúng tôi đã gặp một rắc rối nghiêm trọng với Google Drive.

Chúng tôi không còn có thể cập nhật tài liệu Documents với hình ảnh nữa. Khi ứng dụng iPhone của chúng tôi gửi yêu cầu cập nhật tài liệu Documents với hình ảnh, máy chủ trả về OK nhưng hình ảnh bên trong sẽ không bao giờ được tải lên.

Mã để tạo lại sự cố ở đây.

- (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]; 
} 

Đối với việc sao chép dễ dàng nhất,

  1. Tải mới nhất "Thư viện khách API của Google cho Objective-C".
  2. Mở dự án DriveSample trong XCode.
  3. Thay thế phương thức "- (void) duplicateSelectedFile" bằng mã.
  4. Biên dịch và thực thi ứng dụng mẫu đã sửa đổi, "Nhận danh sách tệp", chọn tệp tài liệu có hình ảnh, sau đó nhấn "Sao chép".
  5. Tệp đã chọn phải được ghi đè bằng cùng một nội dung. Tuy nhiên, tất cả hình ảnh bên trong đều bị mất (trạng thái chờ tải lên không bao giờ chờ đợi).

Nhập FYI, odt/html/rtf/pdf không hoạt động. Tuy nhiên, docx import hoạt động.

Vui lòng khắc phục sự cố càng sớm càng tốt.

Cảm ơn sự hỗ trợ của bạn.

Trả lời

0
(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]; 

    } 

} 
Các vấn đề liên quan