【问题标题】:Google drive API - upload issues - "bad request"Google drive API - 上传问题 - “错误请求”
【发布时间】:2012-12-30 04:50:18
【问题描述】:

我正在开发 GAE java 应用程序,我需要将 PDF 文件上传到用户的谷歌驱动器,但上传总是失败,我不知道可能出了什么问题,因为我已经检查了几个代码示例。

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;

.
.
.

byte[] pdfContent = <... 52kb PDF file ...>


ByteArrayContent mediaContent = new ByteArrayContent("application/pdf", pdfContent);

  File myPDF = new File();
       myPDF.setTitle("Sample PDF");
       myPDF.setDescription("Sample PDF");

  Drive driveService = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getStoredCredential()).build();
  Drive.Files.Insert insert = driveService.files().insert(hugePDF, mediaContent);

insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();

此上传代码总是出现错误:400 OK

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

我正在使用 Google 驱动器库:google-api-services-drive-v2-rev1-1.7.2-beta.jar

凭据很好,因为我可以从用户的谷歌驱动器列出或下载文件。

【问题讨论】:

    标签: java google-app-engine file-upload google-drive-api google-api-java-client


    【解决方案1】:

    我认为问题出在您的库版本中。当前版本是 v2-rev39-1.12.0-beta。检查http://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API。使用最新的 API 库版本总是更好。当我们错过一次更新时,BigQuery API 出现了很多问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多