How to update already existing file in google drive api v3 java

前端 未结 4 696
太阳男子
太阳男子 2021-02-10 19:35

I have tried with the following code... Without any luck...

private void updateFile(Drive service, String fileId) {
        try {
            File file = new Fil         


        
4条回答
  •  灰色年华
    2021-02-10 20:05

    Source

    Unlike the other answers, this solution allows you to upload without having to create a file for the data on the device first.

     // Create a File containing any metadata changes.
     File metadata = new File().setName(name);
    
     // Convert content to an AbstractInputStreamContent instance.
     ByteArrayContent contentStream = ByteArrayContent.fromString("text/plain", content);
    
    // Update the metadata and contents.
    mDriveService.files().update(fileId, metadata, contentStream).execute();
    

提交回复
热议问题