简体   繁体   中英

How to upload file using Java Google Drive API

I would like to upload a file using Google Drive API. I have looked at Google Drive API for Java and Google Drive API Javadoc , but I don't see anything.

The Uploading Files in Drive API that @Polyov gave you contains a Java code snippet:

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.

There's a Java Quickstart to get you started.

If you're looking for more code samples check this github repo for your reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM