tsaebeht
tsaebeht

Reputation: 1680

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.

Upvotes: 5

Views: 29817

Answers (1)

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17613

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.

Upvotes: 4

Related Questions