2016-08-27 297 views
1

我想使用Google Drive API上傳文件。我看過Google Drive API for JavaGoogle Drive API Javadoc,但我什麼也沒看到。如何使用Java Google Drive API上傳文件

+0

我認爲[這](https://developers.google.com/drive/v3/web/manage-uploads)是你在找什麼? – Polyov

+0

@Polyov不使用Java API – tsaebeht

+0

如果向下滾動到[這裏](https://developers.google.com/drive/v3/web/manage-uploads#importing_to_google_docs_types_wzxhzdk8wzxhzdk9),您會看到他們有多種語言,包括Java。第一部分只涉及REST API的技術方面。 – Polyov

回答

1

在驅動器的API,@Polyov給你包含Java代碼片斷的Uploading Files

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()); 

無論使用哪種語言,概念保持不變樣總會有3種類型的上載,即:簡單的上傳,多部分和可恢復。

有一個Java Quickstart讓你開始。

如果您正在尋找更多的代碼示例,請查看github repo以供參考。

相關問題