2017-12-06 7 views
0

を生成しますサイズ(私はしきい値は正確にはわかりませんが、比較的小さなファイルでも約1.5 MBです)、APIは空白の結果を持つ200応答コードを返します(通常はpdfデータをバイトストリームとして格納する必要があります)。 export test screenshot "ファイル - >ダウンロード - > Pdf"コマンドを使用して、GoogleDrive/GoogleDocのUIでファイルを正常にエクスポートできます.despそれは少し時間がかかります。あなたが輸出をしようとするアクセスできるように、ここでGoogleドライブアピPDFエクスポートは、私はPDFファイルとしてGoogleドキュメントを取得するために、輸出GoogleドライブAPIを使用しています空の応答

テスト(Googleドキュメントからエクスポート1.180キロバイト)のために使用されるファイルですが、私はそれを共有する:ここで https://docs.google.com/document/d/18Cz7kHfEiDLeTWHyyoOi6U4kFQDMeg0D-CCJzILMMCk/edit?usp=sharing

は、私が実行するために使用しています(Java)のコードです操作:

@Override 
public GoogleDriveDocumentContent downloadFileContentAsPDF(String executionGoogleUser, String fileId) { 

    GoogleDriveDocumentContent documentContent = new GoogleDriveDocumentContent(); 

    String conversionMimeType = "application/pdf"; 

    try { 

     getLogger().info("GDrive APIs - Downloading file content in PDF format ..."); 

     InputStream gDriveFileData = getDriveService(executionGoogleUser).files() 
       .export(fileId, conversionMimeType) 
       .executeMediaAsInputStream(); 

     getLogger().info("GDrive APIs - File content as PDF format downloaded."); 

     documentContent.setFileName(null); 
     documentContent.setMimeType(conversionMimeType); 
     documentContent.setData(gDriveFileData); 

    } catch (IOException e) { 
     throw new RuntimeException(e); 
    } 

    return documentContent; 

} 

誰もが同じ問題を抱えており、解決方法を知っていますか? 目標はGoogle Docからpdfを生成することです。私はあなたがGoogleドライブではなく、ストレージサービスのためにそれを変更する必要がありますdownloadederメディアを使って試してみてくださいだと思う

おかげ

+0

からリッピングあなたがダウンロードをプリフォームするために使用しているコードを含めることができますか? – DaImTo

+0

もちろん、私はこの問題を編集していますが、Google APIのドキュメントページからapiを試しても同じ問題が発生します:https://developers.google.com/drive/v3/reference/files/export – user1781028

+0

Googlesのドキュメントページはテスト用に大きなファイルをダウンロードするためのものではありません。 – DaImTo

答えて

0

{ 
    // Create the service using the client credentials. 
    var storageService = new StorageService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credential, 
      ApplicationName = "APP_NAME_HERE" 
     }); 
    // Get the client request object for the bucket and desired object. 
    var getRequest = storageService.Objects.Get("BUCKET_HERE", "OBJECT_HERE"); 
    using (var fileStream = new System.IO.FileStream(
     "FILE_PATH_HERE", 
     System.IO.FileMode.Create, 
     System.IO.FileAccess.Write)) 
    { 
     // Add a handler which will be notified on progress changes. 
     // It will notify on each chunk download and when the 
     // download is completed or failed. 
     getRequest.MediaDownloader.ProgressChanged += Download_ProgressChanged; 
     getRequest.Download(fileStream); 
    } 
} 

static void Download_ProgressChanged(IDownloadProgress progress) 
{ 
    Console.WriteLine(progress.Status + " " + progress.BytesDownloaded); 
} 

コードはhere

+0

ありがとうございますが、私の目標は、大きなファイルをダウンロードするのではなく、Google DocからPDFを生成することです。たとえpdfがダウンロードされずにドライブ上に生成されたとしても問題ありません。この方法で解決策がありますか? – user1781028

+0

file.exportが生成しないファイルをダウンロードしようとしているからではありません。あなたのドライブ上で、https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents後で再アップロードする必要があります。 。 – DaImTo

+0

はい私は知っている、これは私がすでにしていることです。しかし、エクスポートファイルは大きなファイルでは機能しません。 MediaDownloaderを使用して、まだ生成されていないファイルをダウンロードすることはできません。あなたは他の解決策を知っていますか? – user1781028

関連する問題