简体   繁体   English

如何使用 Java Google Drive API 上传文件

[英]How to upload file using Java Google Drive API

I would like to upload a file using Google Drive API.我想使用 Google Drive API 上传文件。 I have looked at Google Drive API for Java and Google Drive API Javadoc , but I don't see anything.我看过Google Drive API for JavaGoogle Drive API Javadoc ,但我什么也没看到。

The Uploading Files in Drive API that @Polyov gave you contains a Java code snippet: @Polyov 为您提供的 Drive API 中的上传文件包含一个 Java 代码片段:

File fileMetadata = new File();
fileMetadata.setName("My Report");
fileMetadata.setMimeType("application/vnd.google-apps.spreadsheet");

java.io.File filePath = new java.io.File("files/report.csv");
FileContent mediaContent = new FileContent("text/csv", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());

Whichever language you use, the concepts remain the same like there will always be the 3 types of uploading, namely: simple upload, multipart and resumable.无论您使用哪种语言,概念都保持不变,就像总是有 3 种上传类型,即:简单上传、分段上传和可恢复上传。

There's a Java Quickstart to get you started.有一个Java 快速入门可以帮助您入门。

If you're looking for more code samples check this github repo for your reference.如果您正在寻找更多代码示例,请查看此github 存储库以供您参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用java api将文件上传到谷歌驱动器 - upload file into google drive using java api 如何使用drive api java从谷歌驱动器下载文件? - How to download a file from google drive using drive api java? 如何使用Java API在Google驱动器中上传Excel工作表 - how to upload an excel sheet in google drive using java api 如何使用 Java Google Drive API 创建文件夹动态和上传多个文件 - How to create folder dynamic and upload multiples file using Java Google Drive API 使用 Java 和 Google Drive API V3 将文件上传到共享的 Google Drive 位置? - Upload a file to shared google drive location using Java with Google Drive API V3? 使用Google Drive Api上传文件 - Upload file using Google Drive Api Java Google Drive Android API,上传后获取文件ID - Java Google Drive Android API, get file ID after upload 如何使用Java中的Google Drive API库强制从Google Team Drive下载文件 - How to force download of file from Google Team Drive using Google Drive API libraries in Java 如何使用 Google Drive Java API v3 复制 Google Drive 上的文件? - How do I copy a file on a Google Drive using v3 of the Google Drive Java API? 如何使用Java-Google Docs Api将文件上传到Google驱动器? - How to upload files to google drive using java-Google Docs Api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM