Google drive api 将文件插入Google驱动器-MIME类型不正确

Google drive api 将文件插入Google驱动器-MIME类型不正确,google-drive-api,Google Drive Api,我正试图将文件插入我的谷歌硬盘 我使用我在这里找到的方法: 签名如下: /** * Insert new file. * * @param service Drive API service instance. * @param title Title of the file to insert, including the extension. * @param description Description of the file to insert. *

我正试图将文件插入我的谷歌硬盘

我使用我在这里找到的方法:

签名如下:

/**
   * Insert new file.
   *
   * @param service Drive API service instance.
   * @param title Title of the file to insert, including the extension.
   * @param description Description of the file to insert.
   * @param parentId Optional parent folder's ID.
   * @param mimeType MIME type of the file to insert.
   * @param filename Filename of the file to insert.
   * @return Inserted file metadata if successful, {@code null} otherwise.
   */
   private static File insertFile(Drive service, String title, String description,
  String parentId, String mimeType, String filename);
这是我在主要部分所做的:

public static void main(String[] args) throws IOException {
// Build a new authorized API client service.
Drive service = getDriveService();

java.io.File fi = new java.io.File("/home/davide/Scrivania/test.txt");
if (!fi.exists()) {
    fi.createNewFile();
}

insertFile(service, "test.txt", "JSON string of HashMap",
"/", "txt", "/home/davide/Scrivania/test.txt");
我不知道我是否设置了正确的parentId,文档告诉我它是可选的

但发现的错误是:

An error occured: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Media type 'txt' is not supported. Valid media types: [*/*]",
    "reason" : "badContent"
  } ],
  "message" : "Media type 'txt' is not supported. Valid media types: [*/*]"
}
更新

对于文本/纯MIME类型,错误为:

An error occured: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "location" : "file",
    "locationType" : "other",
    "message" : "File not found: /",
    "reason" : "notFound"
  } ],
  "message" : "File not found: /"
}

解决方案

parentId不正确


我做了
insertFile(服务,“file.txt”、“description”、“text/plain”、“home/davide/Scrivania/test.txt”)和工程。

解决方案

parentId不正确


我做了
insertFile(服务,“file.txt”、“description”、“text/plain”、“home/davide/Scrivania/test.txt”)和工作。

txt
不是有效的(MIME类型)。您可能想用
text/plain
代替
mimeType
参数。@PhilRoss,我试过了。不再工作,请查看上面的更新。请整理您的问题并将解决方案作为答案发布。否则它可能会被西班牙宗教法庭否决。
txt
不是有效的(MIME类型)。您可能想用
text/plain
代替
mimeType
参数。@PhilRoss,我试过了。不再工作,请查看上面的更新。请整理您的问题并将解决方案作为答案发布。否则它可能会被西班牙宗教法庭否决。