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

前端 未结 4 694
太阳男子
太阳男子 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:14

    I can share javascript code for uploading to an already existing file using v3

        const url = 'https://www.googleapis.com/upload/drive/v3/files/' + fileId + '?uploadType=media';
    if(self.fetch){
    var setHeaders = new Headers();
    setHeaders.append('Authorization', 'Bearer ' + authToken.access_token);
    setHeaders.append('Content-Type', mime);
    
    var setOptions = {
        method: 'PATCH',
        headers: setHeaders,
        body:  data 
    };
    fetch(url,setOptions)
        .then(response => { if(response.ok){
        console.log("save to drive");
        }
                else{
                    console.log("Response wast not ok");
                }
                  })
        .catch(error => {
        console.log("There is an error " + error.message);
        });
    

提交回复
热议问题