简体   繁体   中英

How can i move the file or folder to another folder in google drive api?

I did everything as in the documentation ( https://developers.google.com/drive/api/v3/folder#inserting_a_file_in_a_folder ). But that doesn't work for me. I have corrected this script a bit:

window.gapi.client.drive.files.get({
        fileId: fileId,
        fields: 'parents'
      }).then(res => {
        console.log(res)
        window.gapi.client.drive.files.update({
          fileId: this.fileData.id,
          addParents: folderId,
          removeParents: res.result.parents[0],
          fields: 'id, parents'
        }).then(res => {
          console.log(res)
        })
      })

It now moves the file to a different location, but does not delete the current location. That is, after working out my code, it is like copying a file, and not moving it.

The code snippet you are using removes only the first parent.

In order to remove all the parents correctly you will have to add the following line to your code:

var previousParents = res.result.parents.join(',');

And when calling the update method, you will have to remove previousParents :

removeParents: previousParents,

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