1

我正在成功地将文件上传到谷歌驱动器,但是在设置转换标志时遇到了困难。

以下是我尝试的,基于我找到的参考文件。

谁能建议我可能做错了什么?

          java.io.File fileContent = new java.io.File(csvfilepath);
          FileContent mediaContent = new FileContent("text/csv", fileContent);

          // File's metadata.
          File body = new File();
          body.setTitle(fileContent.getName());
          body.setMimeType("text/csv");

          File file = service.files().insert(body, mediaContent);//.execute();
          file.setConvert(true);
          file.execute();

          if (file != null) {
            showToast("Data Uploaded: " + file.getTitle());

https://google-api-client-libraries.appspot.com/documentation/drive/v2/java/latest/com/google/api/services/drive/Drive.Files.Insert.html

4

1 回答 1

3

您正在尝试将转换标志设置为错误的对象,尝试用以下代码替换您的代码:

java.io.File fileContent = new java.io.File(csvfilepath);
FileContent mediaContent = new FileContent("text/csv", fileContent);

// File's metadata.
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("text/csv");

// THIS IS THE NEW CODE
Insert request = service.files().insert(body, mediaContent);
request.setConvert(true);
File file = request.execute();
// END OF NEW CODE

if (file != null) {
  showToast("Data Uploaded: " + file.getTitle());
}
于 2013-01-07T22:16:54.300 回答