[英]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 Java和Google 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.